fix(core): Handle invalid Redis stream IDs in SSE endpoint - #54
Open
sentry[bot] wants to merge 1 commit into
Open
fix(core): Handle invalid Redis stream IDs in SSE endpoint#54sentry[bot] wants to merge 1 commit into
sentry[bot] wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #54 +/- ##
==========================================
- Coverage 92.65% 92.62% -0.03%
==========================================
Files 100 100
Lines 8250 8262 +12
Branches 705 705
==========================================
+ Hits 7644 7653 +9
- Misses 460 463 +3
Partials 146 146
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
This PR addresses an issue where the
/optimize/{job_id}/eventsSSE endpoint, when backed by Redis, would crash with aResponseError: Invalid stream ID specified as stream command argumentif the client provided a malformedLast-Event-IDheader (e.g., 'invalid').The root cause was that
RedisJobStore.stream_eventspassed the client-controlledafter_id(derived fromLast-Event-ID) directly to Redis'sxreadcommand without validation. A truthy but malformed value would bypass theafter_id or "0-0"fallback, leading to the Redis error.The fix introduces a
_normalize_stream_idhelper function that validates the providedafter_id. Ifafter_idisNone, empty, or does not conform to the expected Redis stream ID format (<ms>-<seq>), it now correctly defaults to"0-0". This ensures that streaming always starts from a valid point, preventing theResponseErrorand mirroring the robust behavior already present inMemoryJobStorefor invalid cursors.Fixes NURSE-SCHEDULING-3D