Context
Identified during review of PR #16 (CAS reconnect on inactive broker). The checkReconnect() method added by that PR is guarded by a mutex, but the broader sendAndRecv() call path is not fully serialized against the reconnect flow.
Problem
When multiple async operations call sendAndRecv() concurrently and one triggers a reconnect:
- Operation A detects socket death, enters
checkReconnect()
- Operation B is mid-flight in
sendAndRecv() writing to the old socket
checkReconnect() replaces the socket while B is still writing
- B's data goes to the new (reset) socket → protocol state corruption
Additionally
The socket error handler silently swallows errors:
socket.on('error', () => {}); // silent — should log
This masks real connection problems. Replace with proper logging.
Proposed Fix
- Serialize sendAndRecv against reconnect: acquire the same mutex (or a dedicated connection mutex) around the full
sendAndRecv() lifecycle, not just around checkReconnect().
- Add error logging: replace silent socket error handler with
this.logger?.error(...) or equivalent.
References
Context
Identified during review of PR #16 (CAS reconnect on inactive broker). The
checkReconnect()method added by that PR is guarded by a mutex, but the broadersendAndRecv()call path is not fully serialized against the reconnect flow.Problem
When multiple async operations call
sendAndRecv()concurrently and one triggers a reconnect:checkReconnect()sendAndRecv()writing to the old socketcheckReconnect()replaces the socket while B is still writingAdditionally
The socket error handler silently swallows errors:
This masks real connection problems. Replace with proper logging.
Proposed Fix
sendAndRecv()lifecycle, not just aroundcheckReconnect().this.logger?.error(...)or equivalent.References