Skip to content

Commit

Permalink
fix(app): fix the way the ssh tunnel connection was closed
Browse files Browse the repository at this point in the history
  • Loading branch information
danvergara committed Jan 6, 2025
1 parent b43efc8 commit db64368
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ import (

// App Struct.
type App struct {
t *tui.Tui
c *client.Client
t *tui.Tui
c *client.Client
sc *sshdb.SSHConfig
}

// New bootstrap a new application.
func New(opts command.Options) (*App, error) {
var sshConfig *sshdb.SSHConfig
var sc *sshdb.SSHConfig

if opts.SSHHost != "" {
sshConfig = sshdb.New(
sc = sshdb.New(
sshdb.WithDBDriver(opts.Driver),
sshdb.WithSShHost(opts.SSHHost),
sshdb.WithSShPort(opts.SSHPort),
Expand All @@ -29,11 +30,9 @@ func New(opts command.Options) (*App, error) {
sshdb.WithDBDURL(opts.URL),
)

if err := sshConfig.SSHTunnel(); err != nil {
if err := sc.SSHTunnel(); err != nil {
return nil, err
}

defer sshConfig.Close()
}

c, err := client.New(opts)
Expand All @@ -47,8 +46,9 @@ func New(opts command.Options) (*App, error) {
}

app := App{
t: t,
c: c,
c: c,
t: t,
sc: sc,
}

return &app, nil
Expand All @@ -57,6 +57,10 @@ func New(opts command.Options) (*App, error) {
// Run runs the application.
func (a *App) Run() error {
defer func() {
if a.sc != nil {
_ = a.sc.Close()
}

_ = a.c.DB().Close()
}()

Expand Down
2 changes: 1 addition & 1 deletion pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (c *Client) ShowTablesPerDB(database string) ([]string, error) {
}

switch c.driver {
case drivers.PostgreSQL, drivers.Postgres, drivers.MySQL:
case drivers.PostgreSQL, drivers.Postgres, drivers.PostgresSSH, drivers.MySQL:
db, ok = c.dbs[database]
if !ok {
return nil, fmt.Errorf("connection with %s database not found", database)
Expand Down

0 comments on commit db64368

Please sign in to comment.