Skip to content

Commit

Permalink
fix: emit error event on connack timeout (#1781)
Browse files Browse the repository at this point in the history
* fix: emit `error` event on connack timeout

* fix: force close client
  • Loading branch information
robertsLando committed Jan 24, 2024
1 parent 342d047 commit 56e6e23
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/client.ts
Expand Up @@ -850,6 +850,7 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
this.log(
'!!connectTimeout hit!! Calling _cleanUp with force `true`',
)
this.emit('error', new Error('connack timeout'))
this._cleanUp(true)
}, this.options.connectTimeout)

Expand Down
12 changes: 12 additions & 0 deletions test/abstract_client.ts
Expand Up @@ -3004,6 +3004,18 @@ export default function abstractTest(server, config, ports) {
}, 50)
})

it('should emit connack timeout error', function _test(t, done) {
const client = connect({
connectTimeout: 0,
reconnectPeriod: 5000,
})

client.on('error', (err) => {
assert.equal(err.message, 'connack timeout')
client.end(true, done)
})
})

it(
'should resend in-flight QoS 1 publish messages from the client',
{
Expand Down

0 comments on commit 56e6e23

Please sign in to comment.