Skip to content

Commit

Permalink
session: do not assign conns to nil on Close()
Browse files Browse the repository at this point in the history
Let the runtime handle garbage collection, and avoid errors where
methods like Unsubscribe() are called after Close().
  • Loading branch information
enr0n committed Feb 11, 2025
1 parent f234f72 commit 6850dd5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
7 changes: 1 addition & 6 deletions vici/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,7 @@ func newEventListener(cc *clientConn) *eventListener {

// Close closes the event channel.
func (el *eventListener) Close() error {
if el.cc != nil {
el.cc.Close()
el.cc = nil
}

return nil
return el.cc.Close()
}

// listen is responsible for receiving all packets from the daemon. This includes
Expand Down
13 changes: 2 additions & 11 deletions vici/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,12 @@ func (s *Session) newClientConn() (*clientConn, error) {

// Close closes the vici session.
func (s *Session) Close() error {
if err := s.el.Close(); err != nil {
return err
}
err := e.el.Close()

Check failure on line 105 in vici/session.go

View workflow job for this annotation

GitHub Actions / test (1.23.x, ubuntu-latest)

undefined: e

Check failure on line 105 in vici/session.go

View workflow job for this annotation

GitHub Actions / lint

undefined: e (typecheck)

s.mu.Lock()
defer s.mu.Unlock()
if s.cc != nil {
if err := s.cc.Close(); err != nil {
return err
}

s.cc = nil
}

return nil
return errors.Join(err, s.cc.Close())
}

// SessionOption is used to specify additional options
Expand Down

0 comments on commit 6850dd5

Please sign in to comment.