Skip to content

Commit 8d88f33

Browse files
backport of commit 1fe69f2 (#147)
Co-authored-by: Robert <17119716+robmonte@users.noreply.github.com>
1 parent cac1d16 commit 8d88f33

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: BUG FIXES
2+
body: Refresh the connection upon expiration
3+
time: 2025-09-09T16:50:37.281682-05:00
4+
custom:
5+
Issue: "134"

connection_producer.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ import (
1010
"database/sql"
1111
"encoding/pem"
1212
"fmt"
13-
"github.com/hashicorp/errwrap"
14-
log "github.com/hashicorp/go-hclog"
15-
"github.com/hashicorp/go-secure-stdlib/parseutil"
16-
"github.com/hashicorp/vault/sdk/database/helper/dbutil"
1713
"net/url"
1814
"regexp"
1915
"sync"
2016
"time"
2117

18+
"github.com/hashicorp/errwrap"
19+
log "github.com/hashicorp/go-hclog"
20+
"github.com/hashicorp/go-secure-stdlib/parseutil"
21+
"github.com/hashicorp/vault/sdk/database/helper/dbutil"
22+
2223
"github.com/hashicorp/vault/sdk/database/helper/connutil"
2324
"github.com/mitchellh/mapstructure"
2425
"github.com/snowflakedb/gosnowflake"
@@ -149,8 +150,14 @@ func (c *snowflakeConnectionProducer) Connection(ctx context.Context) (interface
149150
return nil, connutil.ErrNotInitialized
150151
}
151152

153+
// If we already have a DB, test it and return
152154
if c.snowflakeDB != nil {
153-
return c.snowflakeDB, nil
155+
if err := c.snowflakeDB.PingContext(ctx); err == nil {
156+
return c.snowflakeDB, nil
157+
}
158+
// If the ping was unsuccessful, close it and ignore errors as we'll be
159+
// reestablishing anyways
160+
c.snowflakeDB.Close()
154161
}
155162

156163
var db *sql.DB

0 commit comments

Comments
 (0)