Skip to content

Commit 0a1518b

Browse files
committed
Error all outstanding tokens at disconnection
If connected with cleansession false you could expect to get outstanding message confirmations after reconnecting, but actually this would only occur with QoS2 publishes at PUBREC, QoS1 and QoS2 after PUBREL will be assumed by the sender to have been received, this will cause tokens to hang. This change causes all outstanding tokens at disconnection time to be completed as errored.
1 parent 64d8663 commit 0a1518b

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

Diff for: client.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,7 @@ func (c *client) internalConnLost(err error) {
437437
c.closeStop()
438438
c.conn.Close()
439439
c.workers.Wait()
440-
if c.options.CleanSession {
441-
c.messageIds.cleanUp()
442-
}
440+
c.messageIds.cleanUp()
443441
if c.options.AutoReconnect {
444442
c.setConnected(reconnecting)
445443
go c.reconnect()

Diff for: token_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package mqtt
2+
3+
import (
4+
"testing"
5+
"time"
6+
)
7+
8+
func TestWaitTimeout(t *testing.T) {
9+
b := baseToken{}
10+
11+
if b.WaitTimeout(time.Second) {
12+
t.Fatal("Should have failed")
13+
}
14+
}

0 commit comments

Comments
 (0)