Enhance service bus handling of invalid JSON in receive_message function#4932
Open
JC-wk wants to merge 5 commits into
Open
Enhance service bus handling of invalid JSON in receive_message function#4932JC-wk wants to merge 5 commits into
JC-wk wants to merge 5 commits into
Conversation
added 2 commits
June 9, 2026 09:27
…ovide fix for the infinite looped service bus issue
Contributor
There was a problem hiding this comment.
Pull request overview
Improves the resource processor’s Service Bus session receiver loop to tolerate malformed/non-JSON messages by dead-lettering them and continuing processing, instead of crashing the runner.
Changes:
- Dead-letter malformed Service Bus messages on
json.JSONDecodeErrorand skip further processing of that message. - Add a unit test covering the malformed JSON path in
receive_message. - Bump
resource_processorversion and add an Unreleased changelog entry.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| resource_processor/vmss_porter/runner.py | Dead-letters invalid JSON messages and continues the receive loop. |
| resource_processor/tests_rp/test_runner.py | Adds a unit test to verify invalid JSON messages are dead-lettered and not completed. |
| resource_processor/_version.py | Patch version bump. |
| CHANGELOG.md | Adds an Unreleased BUG FIXES entry for the change. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Unit Test Results0 tests 0 ✅ 0s ⏱️ Results for commit 59a309a. ♻️ This comment has been updated with latest results. |
Collaborator
|
/test 59a309a |
|
🤖 pr-bot 🤖 🏃 Running tests: https://github.com/microsoft/AzureTRE/actions/runs/27306698867 (with refid (in response to this comment from @rudolphjacksonm) |
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.
What is being addressed
Service bus will now skip malformed payloads instead of crashing
How is this addressed
Summary of Changes
• Caught json.JSONDecodeError when deserializing the Service Bus message payload.
• Sent the malformed message to the dead-letter queue via await receiver.dead_letter_message(msg, reason="InvalidJSON") to clear it from the queue and aid in troubleshooting.
• Added a continue statement inside the except block to prevent processing of empty/malformed message structures, avoiding downstream TypeError crashes.
• Added a new unit test test_receive_message_bad_json to simulate receiving a malformed/non-JSON payload, asserting that:
• The message is successfully sent to the dead-letter queue.
• The message is not processed or marked complete (i.e. skipped).