Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(test): close open connections #1911

Merged
merged 9 commits into from
Aug 1, 2024
Merged
5 changes: 4 additions & 1 deletion src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,10 @@ export type OnMessageCallback = (
export type OnPacketCallback = (packet: Packet) => void
export type OnCloseCallback = () => void
export type OnErrorCallback = (error: Error | ErrorWithReasonCode) => void
export type PacketCallback = (error?: Error, packet?: Packet) => any
export type PacketCallback = (
error?: Error | ErrorWithReasonCode,
packet?: Packet,
) => any
export type CloseCallback = (error?: Error) => void

export interface MqttClientEventCallbacks {
Expand Down
14 changes: 9 additions & 5 deletions src/lib/handlers/ack.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Other Socket Errors: EADDRINUSE, ECONNRESET, ENOTFOUND, ETIMEDOUT.

import { PacketHandler } from '../shared'
import { PacketHandler, ErrorWithReasonCode } from '../shared'

export const ReasonCodes = {
0: '',
Expand Down Expand Up @@ -82,8 +82,10 @@ const handleAck: PacketHandler = (client, packet) => {
const pubackRC = packet.reasonCode
// Callback - we're done
if (pubackRC && pubackRC > 0 && pubackRC !== 16) {
err = new Error(`Publish error: ${ReasonCodes[pubackRC]}`)
err.code = pubackRC
err = new ErrorWithReasonCode(
`Publish error: ${ReasonCodes[pubackRC]}`,
pubackRC,
)
client['_removeOutgoingAndStoreMessage'](messageId, () => {
cb(err, packet)
})
Expand All @@ -102,8 +104,10 @@ const handleAck: PacketHandler = (client, packet) => {
const pubrecRC = packet.reasonCode

if (pubrecRC && pubrecRC > 0 && pubrecRC !== 16) {
err = new Error(`Publish error: ${ReasonCodes[pubrecRC]}`)
err.code = pubrecRC
err = new ErrorWithReasonCode(
`Publish error: ${ReasonCodes[pubrecRC]}`,
pubrecRC,
)
client['_removeOutgoingAndStoreMessage'](messageId, () => {
cb(err, packet)
})
Expand Down
Loading