connection-deadlock, socket: improve socket end conditions
This commit is contained in:
+12
-11
@@ -673,7 +673,7 @@ export const makeSocket = (config: SocketConfig) => {
|
||||
it could be that the network is down
|
||||
*/
|
||||
if (diff > keepAliveIntervalMs + 5000) {
|
||||
end(new Boom('Connection was lost', { statusCode: DisconnectReason.connectionLost }))
|
||||
void end(new Boom('Connection was lost', { statusCode: DisconnectReason.connectionLost }))
|
||||
} else if (ws.isOpen) {
|
||||
// if its all good, send a keep alive request
|
||||
query({
|
||||
@@ -728,7 +728,7 @@ export const makeSocket = (config: SocketConfig) => {
|
||||
})
|
||||
}
|
||||
|
||||
end(new Boom(msg || 'Intentional Logout', { statusCode: DisconnectReason.loggedOut }))
|
||||
void end(new Boom(msg || 'Intentional Logout', { statusCode: DisconnectReason.loggedOut }))
|
||||
}
|
||||
|
||||
const requestPairingCode = async (phoneNumber: string, customPairingCode?: string): Promise<string> => {
|
||||
@@ -828,14 +828,15 @@ export const makeSocket = (config: SocketConfig) => {
|
||||
await validateConnection()
|
||||
} catch (err: any) {
|
||||
logger.error({ err }, 'error in validating connection')
|
||||
end(err)
|
||||
void end(err)
|
||||
}
|
||||
})
|
||||
ws.on('error', mapWebSocketError(end))
|
||||
ws.on('close', () => end(new Boom('Connection Terminated', { statusCode: DisconnectReason.connectionClosed })))
|
||||
ws.on('close', () => void end(new Boom('Connection Terminated', { statusCode: DisconnectReason.connectionClosed })))
|
||||
// the server terminated the connection
|
||||
ws.on('CB:xmlstreamend', () =>
|
||||
end(new Boom('Connection Terminated by Server', { statusCode: DisconnectReason.connectionClosed }))
|
||||
ws.on(
|
||||
'CB:xmlstreamend',
|
||||
() => void end(new Boom('Connection Terminated by Server', { statusCode: DisconnectReason.connectionClosed }))
|
||||
)
|
||||
// QR gen
|
||||
ws.on('CB:iq,type:set,pair-device', async (stanza: BinaryNode) => {
|
||||
@@ -863,7 +864,7 @@ export const makeSocket = (config: SocketConfig) => {
|
||||
|
||||
const refNode = refNodes.shift()
|
||||
if (!refNode) {
|
||||
end(new Boom('QR refs attempts ended', { statusCode: DisconnectReason.timedOut }))
|
||||
void end(new Boom('QR refs attempts ended', { statusCode: DisconnectReason.timedOut }))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -896,7 +897,7 @@ export const makeSocket = (config: SocketConfig) => {
|
||||
await sendNode(reply)
|
||||
} catch (error: any) {
|
||||
logger.info({ trace: error.stack }, 'error in pairing')
|
||||
end(error)
|
||||
void end(error)
|
||||
}
|
||||
})
|
||||
// login complete
|
||||
@@ -956,16 +957,16 @@ export const makeSocket = (config: SocketConfig) => {
|
||||
|
||||
const { reason, statusCode } = getErrorCodeFromStreamError(node)
|
||||
|
||||
end(new Boom(`Stream Errored (${reason})`, { statusCode, data: reasonNode || node }))
|
||||
void end(new Boom(`Stream Errored (${reason})`, { statusCode, data: reasonNode || node }))
|
||||
})
|
||||
// stream fail, possible logout
|
||||
ws.on('CB:failure', (node: BinaryNode) => {
|
||||
const reason = +(node.attrs.reason || 500)
|
||||
end(new Boom('Connection Failure', { statusCode: reason, data: node.attrs }))
|
||||
void end(new Boom('Connection Failure', { statusCode: reason, data: node.attrs }))
|
||||
})
|
||||
|
||||
ws.on('CB:ib,,downgrade_webclient', () => {
|
||||
end(new Boom('Multi-device beta not joined', { statusCode: DisconnectReason.multideviceMismatch }))
|
||||
void end(new Boom('Multi-device beta not joined', { statusCode: DisconnectReason.multideviceMismatch }))
|
||||
})
|
||||
|
||||
ws.on('CB:ib,,offline_preview', async (node: BinaryNode) => {
|
||||
|
||||
@@ -48,7 +48,7 @@ describe('Connection Deadlock Test', () => {
|
||||
})
|
||||
)
|
||||
|
||||
sock.end(new Error('Test completed'))
|
||||
await sock.end(new Error('Test completed'))
|
||||
await clear()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user