@@ -456,31 +456,26 @@ func (c *client) Disconnect(quiesce uint) {
456
456
457
457
status := atomic .LoadUint32 (& c .status )
458
458
c .setConnected (disconnected )
459
- if status == connected {
460
- DEBUG .Println (CLI , "disconnecting" )
461
459
462
- dm := packets .NewControlPacket (packets .Disconnect ).(* packets.DisconnectPacket )
463
- dt := newToken (packets .Disconnect )
464
- disconnectSent := false
465
- select {
466
- case c .oboundP <- & PacketAndToken {p : dm , t : dt }:
467
- disconnectSent = true
468
- case <- c .commsStopped :
469
- WARN .Println ("Disconnect packet could not be sent because comms stopped" )
470
- case <- time .After (time .Duration (quiesce ) * time .Millisecond ):
471
- WARN .Println ("Disconnect packet not sent due to timeout" )
472
- }
473
-
474
- // wait for work to finish, or quiesce time consumed
475
- if disconnectSent {
476
- DEBUG .Println (CLI , "calling WaitTimeout" )
477
- dt .WaitTimeout (time .Duration (quiesce ) * time .Millisecond )
478
- DEBUG .Println (CLI , "WaitTimeout done" )
479
- }
480
- } else {
460
+ if status != connected {
481
461
WARN .Println (CLI , "Disconnect() called but not connected (disconnected/reconnecting)" )
462
+ return
482
463
}
483
464
465
+ DEBUG .Println (CLI , "disconnecting" )
466
+ dm := packets .NewControlPacket (packets .Disconnect ).(* packets.DisconnectPacket )
467
+ dt := newToken (packets .Disconnect )
468
+ select {
469
+ case c .oboundP <- & PacketAndToken {p : dm , t : dt }:
470
+ // wait for work to finish, or quiesce time consumed
471
+ DEBUG .Println (CLI , "calling WaitTimeout" )
472
+ dt .WaitTimeout (time .Duration (quiesce ) * time .Millisecond )
473
+ DEBUG .Println (CLI , "WaitTimeout done" )
474
+ case <- c .commsStopped :
475
+ WARN .Println ("Disconnect packet could not be sent because comms stopped" )
476
+ case <- time .After (time .Duration (quiesce ) * time .Millisecond ):
477
+ WARN .Println ("Disconnect packet not sent due to timeout" )
478
+ }
484
479
}
485
480
486
481
// forceDisconnect will end the connection with the mqtt broker immediately (used for tests only)
0 commit comments