Skip to content

Commit 71f9814

Browse files
committed
fix: issue 675:goroutine leak when connectionUp(true) return error
1 parent 386b731 commit 71f9814

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

client.go

+4-18
Original file line numberDiff line numberDiff line change
@@ -601,26 +601,12 @@ func (c *client) startCommsWorkers(conn net.Conn, connectionUp connCompletedFn,
601601
c.workers.Add(1) // Done will be called when ackOut is closed
602602
ackOut := c.msgRouter.matchAndDispatch(incomingPubChan, c.options.Order, c)
603603

604-
// The connection is now ready for use (we spin up a few go routines below). It is possible that
605-
// Disconnect has been called in the interim...
604+
// The connection is now ready for use (we spin up a few go routines below).
605+
// It is possible that Disconnect has been called in the interim...
606+
// issue 675:we will allow the connection to complete before the Disconnect is allowed to proceed
607+
// as if a Disconnect event occurred immediately after connectionUp(true) completed.
606608
if err := connectionUp(true); err != nil {
607609
ERROR.Println(CLI, err)
608-
609-
/* issue 675:goroutine leak when connectionUp(true) return error
610-
* Only when status == disconnecting will this logic be executed.
611-
* The goroutine that changes the status to disconnecting should be
612-
* responsible for resource cleanup (which is indeed how it is done).
613-
*
614-
* Being disconnected right when the connection is established is a special case.
615-
* Even if we remove this check for connectionUp(true), the program must still function correctly,
616-
* as if a Disconnect event occurred immediately after connectionUp(true) completed.
617-
*/
618-
619-
//close(c.stop) // Tidy up anything we have already started
620-
//close(incomingPubChan)
621-
//c.workers.Wait()
622-
//c.conn.Close()
623-
//c.conn = nil
624610
}
625611

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

0 commit comments

Comments
 (0)