Skip to content

Commit

Permalink
fix: issue 675:goroutine leak when connectionUp(true) return error
Browse files Browse the repository at this point in the history
  • Loading branch information
kiqi007 committed May 20, 2024
1 parent 386b731 commit 71f9814
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,26 +601,12 @@ func (c *client) startCommsWorkers(conn net.Conn, connectionUp connCompletedFn,
c.workers.Add(1) // Done will be called when ackOut is closed
ackOut := c.msgRouter.matchAndDispatch(incomingPubChan, c.options.Order, c)

// The connection is now ready for use (we spin up a few go routines below). It is possible that
// Disconnect has been called in the interim...
// The connection is now ready for use (we spin up a few go routines below).
// It is possible that Disconnect has been called in the interim...
// issue 675:we will allow the connection to complete before the Disconnect is allowed to proceed
// as if a Disconnect event occurred immediately after connectionUp(true) completed.
if err := connectionUp(true); err != nil {
ERROR.Println(CLI, err)

/* issue 675:goroutine leak when connectionUp(true) return error
* Only when status == disconnecting will this logic be executed.
* The goroutine that changes the status to disconnecting should be
* responsible for resource cleanup (which is indeed how it is done).
*
* Being disconnected right when the connection is established is a special case.
* Even if we remove this check for connectionUp(true), the program must still function correctly,
* as if a Disconnect event occurred immediately after connectionUp(true) completed.
*/

//close(c.stop) // Tidy up anything we have already started
//close(incomingPubChan)
//c.workers.Wait()
//c.conn.Close()
//c.conn = nil
}

DEBUG.Println(CLI, "client is connected/reconnected")
Expand Down

0 comments on commit 71f9814

Please sign in to comment.