Skip to content

Commit

Permalink
Fix race condition blocking cleanup of goroutines (#57)
Browse files Browse the repository at this point in the history
Signed-off-by: Bernhard Schmid <[email protected]>
Co-authored-by: Mirko Lazarevic <[email protected]>
  • Loading branch information
mirko-lazarevic and mirko-lazarevic authored Feb 23, 2023
1 parent c2b759c commit acc7c3f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions fluent/client/ws/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ type connection struct {
writeLock sync.Mutex
stateLock sync.RWMutex
readHandler ReadHandler
closedSig chan struct{}
done chan struct{}
connState ConnState
closeDeadline time.Duration
}

func NewConnection(conn ext.Conn, opts ConnectionOptions) (Connection, error) {
wsc := &connection{
Conn: conn,
closedSig: make(chan struct{}),
done: make(chan struct{}),
connState: ConnStateOpen,
logger: opts.Logger,
}
Expand Down Expand Up @@ -239,7 +239,7 @@ func (wsc *connection) CloseWithMsg(closeCode int, msg string) error {
case <-time.After(wsc.closeDeadline):
// sent a close, but never heard back, close anyway
err = errors.New("close deadline expired")
case <-wsc.closedSig:
case <-wsc.done:
}
}
}
Expand Down Expand Up @@ -285,7 +285,7 @@ func (wsc *connection) runReadLoop(nextMsg chan connMsg) {

close(nextMsg)
wsc.unsetConnState(ConnStateListening)
wsc.closedSig <- struct{}{}
close(wsc.done)
}()

msg := connMsg{}
Expand Down

0 comments on commit acc7c3f

Please sign in to comment.