Skip to content

Commit 56e6e23

Browse files
authored
fix: emit error event on connack timeout (#1781)
* fix: emit `error` event on connack timeout * fix: force close client
1 parent 342d047 commit 56e6e23

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/lib/client.ts

+1
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,7 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
850850
this.log(
851851
'!!connectTimeout hit!! Calling _cleanUp with force `true`',
852852
)
853+
this.emit('error', new Error('connack timeout'))
853854
this._cleanUp(true)
854855
}, this.options.connectTimeout)
855856

test/abstract_client.ts

+12
Original file line numberDiff line numberDiff line change
@@ -3004,6 +3004,18 @@ export default function abstractTest(server, config, ports) {
30043004
}, 50)
30053005
})
30063006

3007+
it('should emit connack timeout error', function _test(t, done) {
3008+
const client = connect({
3009+
connectTimeout: 0,
3010+
reconnectPeriod: 5000,
3011+
})
3012+
3013+
client.on('error', (err) => {
3014+
assert.equal(err.message, 'connack timeout')
3015+
client.end(true, done)
3016+
})
3017+
})
3018+
30073019
it(
30083020
'should resend in-flight QoS 1 publish messages from the client',
30093021
{

0 commit comments

Comments
 (0)