When a new web socket connection is detected, a web socket BTP instance checks if there is an existing web socket connection (this._incomingWs) and closes it:
However, it passes the auth packet from the new web socket connection to _closeIncomingSocket, and gets the request ID from this auth packet:
_closeIncomingSocket (socket: WebSocket, authPacket: BtpPacket) {
socket.removeAllListeners()
socket.once('message', async (data: WebSocket.Data) => {
try {
socket.send(BtpPacket.serializeError({
code: 'F00',
name: 'NotAcceptedError',
data: 'This connection has been ended because the user has opened a new connection',
triggeredAt: new Date().toISOString()
}, authPacket.requestId, []))
} catch (e) {
this._log.error('error responding on closed socket', e)
}
socket.close()
})
}
Why is it sending an error response to the old stream with the new request ID, if the new socket is also getting a valid response? Shouldn't this function just remove all listeners and close the socket gracefully? Or send a normal response to the user on the old socket (not error F00)?
When a new web socket connection is detected, a web socket BTP instance checks if there is an existing web socket connection (this._incomingWs) and closes it:
However, it passes the auth packet from the new web socket connection to _closeIncomingSocket, and gets the request ID from this auth packet:
Why is it sending an error response to the old stream with the new request ID, if the new socket is also getting a valid response? Shouldn't this function just remove all listeners and close the socket gracefully? Or send a normal response to the user on the old socket (not error F00)?