fix(retry): resolve message delivery speed

fix(retry): resolve message delivery speed
This commit is contained in:
Renato Alcara
2026-02-26 22:09:18 -03:00
committed by GitHub
parent 416ad47789
commit d73f2d0fc3
4 changed files with 53 additions and 20 deletions
+16 -6
View File
@@ -343,12 +343,22 @@ export const makeSocket = (config: SocketConfig) => {
const msgId = node.attrs.id
const result = await promiseTimeout<any>(timeoutMs, async (resolve, reject) => {
const result = waitForMessage(msgId, timeoutMs).catch(reject)
sendNode(node)
.then(async () => resolve(await result))
.catch(reject)
})
// Register the response listener BEFORE sending — avoids a race where the server
// responds before we start listening. waitForMessage already handles its own
// timeout (returns undefined) and connection-close errors (throws), so we do NOT
// wrap it in a second promiseTimeout. The outer wrapper caused a race condition
// where both timers fired at ~the same deadline: the outer one threw
// Boom('Timed Out') while sendNode was still pending, producing a spurious error
// whose message contained "socket-query" → matched the circuit-breaker's
// "socket" pattern → incorrectly tripped the breaker after 5 timeouts.
const responsePromise = waitForMessage<any>(msgId, timeoutMs)
// Await the send so that real sendNode failures (e.g. serialisation errors)
// are surfaced to the caller immediately rather than silently discarded.
// Socket-close errors are also propagated by waitForMessage via ws.on('close').
await sendNode(node)
const result = await responsePromise
if (result && 'tag' in result) {
assertNodeErrorFree(result)