Repository navigation
fix(message-bus): swallow the CANCELLED error when unsubscribing from Rusi - #60
Merged
Merged
Conversation
… Rusi grpc-js emits 'error' (1 CANCELLED: Cancelled on client) on a duplex stream after call.cancel(). Since #51, unsubscribe removed the stream's 'error' listener before cancelling, so the event had no listener and became an uncaughtException, which shuts down the messaging host after every sendCommandAndReceiveEvent. Attach a no-op 'error' listener before cancelling. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
oncicaradupopovici
approved these changes
Nov 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With the Rusi transport, every
sendCommandAndReceiveEventcrashes the process once the reply event has been received:finallyblock callssubscription.unsubscribe().unsubscriberemoves the stream's'error'/'end'listeners and then callscall.cancel().'error'with status1 CANCELLED(client.js→onReceiveStatus).'error'any more, so Node throws.graceful-shutdowntreats the resultinguncaughtExceptionas unrecoverable and shuts the host down.This started with #51, which began removing the
'error'listener beforecancel(). Before #51, the listener stayed on the stream and just logged the error.Fix
In
unsubscribe, attach a no-op'error'listener before callingcancel(). The CANCELLED error is swallowed and isn't passed on to the subscription's own error listeners. Everything else from #51 is unchanged.Tests
cancel(), as grpc-js does. It failed before the fix withUnhandled error ... CANCELLEDand passes now.message-bustests pass, andtsc --noEmitis clean.Includes a patch changeset for
@totalsoft/message-bus.Not in this PR
After
unsubscribecancels the stream, the'data'handler still tries to ack the reply on it, so the sidecar logs "message was not ACK". That's harmless for a short-lived RPC subscription and is left as is.🤖 Generated with Claude Code