Skip to content

Commit

Permalink
Fix unclosed database sessions and tunnels (#688)
Browse files Browse the repository at this point in the history
  • Loading branch information
sosedoff committed Sep 10, 2023
1 parent 14d8d80 commit 22daaad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ func Disconnect(c *gin.Context) {
return
}

DbClient = nil
successResponse(c, gin.H{"success": true})
}

Expand Down
8 changes: 6 additions & 2 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ func New() (*Client, error) {
}

func NewFromUrl(url string, sshInfo *shared.SSHInfo) (*Client, error) {
var tunnel *Tunnel
var (
tunnel *Tunnel
err error
)

if sshInfo != nil {
if command.Opts.DisableSSH {
Expand All @@ -79,7 +82,7 @@ func NewFromUrl(url string, sshInfo *shared.SSHInfo) (*Client, error) {
fmt.Println("Opening SSH tunnel for:", sshInfo)
}

tunnel, err := NewTunnel(sshInfo, url)
tunnel, err = NewTunnel(sshInfo, url)
if err != nil {
tunnel.Close()
return nil, err
Expand Down Expand Up @@ -524,6 +527,7 @@ func (client *Client) Close() error {
}
defer func() {
client.closed = true
client.tunnel = nil
}()

if client.tunnel != nil {
Expand Down

0 comments on commit 22daaad

Please sign in to comment.