fix(microservices): handle non-json mqtt response packets gracefully - #17534
Open
tushardev-365 wants to merge 1 commit into
Open
fix(microservices): handle non-json mqtt response packets gracefully#17534tushardev-365 wants to merge 1 commit into
tushardev-365 wants to merge 1 commit into
Conversation
ClientMqtt.createResponseCallback parsed every incoming reply with an unguarded JSON.parse. A non-json payload on a subscribed reply topic threw inside the async mqtt message listener, producing an unhandled rejection, and the pending request observable never settled. Every other transport already guards this parse: ClientRedis falls back to the raw content with a debug log, and the mqtt, redis and rmq servers all parse defensively. This applies the same guard ClientRedis uses, passing the raw content to the deserializer.
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.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
ClientMqtt.createResponseCallbackparses every incoming reply with an unguardedJSON.parse:A non-JSON payload arriving on a subscribed reply topic (a plain-text reply from a non-Nest service sharing the broker, a misconfigured publisher, a binary payload) makes the parse throw inside the async
'message'listener. That becomes an unhandled promise rejection, which crashes the process under Node's default policy, and the pending request observable never settles.ClientMqtt is the outlier here. Every sibling transport already guards this exact parse:
ClientRedis.createResponseCallbackwraps it in try/catch and falls back to the raw content with a debug log, and the MQTT, Redis and RMQ servers all parse incoming messages defensively.Issue Number: N/A
What is the new behavior?
The parse is guarded the same way
ClientRedisdoes it: on failure, log at debug level and hand the raw content to the deserializer, so custom deserializers keep working with non-JSON formats and an unparseable stray message can no longer crash the client.Added a spec mirroring the existing
createResponseCallbackcases: a non-JSON buffer must not throw and must reach the deserializer. Verification runs:Does this PR introduce a breaking change?
Other information