Skip to content

Commit

Permalink
fix: always close transport if onopen funcs (or netconf capabilities …
Browse files Browse the repository at this point in the history
…things) error
  • Loading branch information
carlmontanari committed Apr 2, 2024
1 parent 6ed05e3 commit 03bc0c8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions driver/generic/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ func (d *Driver) Open() error {
if err != nil {
d.Logger.Criticalf("error executing generic driver OnOpen, error: %s", err)

// don't leave the channel (and more importantly, the transport) open if we are going to
// return an error
_ = d.Channel.Close()

return err
}
}
Expand Down
10 changes: 9 additions & 1 deletion driver/netconf/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ type Driver struct {

// Open opens the underlying generic.Driver, and by extension the channel.Channel and Transport
// objects. This should be called prior to executing any RPC methods of the Driver.
func (d *Driver) Open() error {
func (d *Driver) Open() (reterr error) {
d.Logger.Debugf(
"opening connection to host '%s' on port '%d'",
d.Transport.Args.Host,
Expand All @@ -218,6 +218,14 @@ func (d *Driver) Open() error {
return err
}

defer func() {
if reterr != nil {
// don't leave the channel (and more importantly, the transport) open if we are going to
// return an error
_ = d.Channel.Close()
}
}()

err = d.processServerCapabilities()
if err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions driver/network/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ func (d *Driver) Open() error {
if err != nil {
d.Logger.Criticalf("error executing network driver OnOpen, error: %s", err)

// don't leave the channel (and more importantly, the transport) open if we are going to
// return an error
_ = d.Channel.Close()

return err
}
}
Expand Down

0 comments on commit 03bc0c8

Please sign in to comment.