Repository navigation
fix: isolate random byte generators per request - #767
Merged
harryjackson merged 1 commit intoNov 16, 2026
Merged
harryjackson merged 1 commit into
harryjackson merged 1 commit into
Conversation
Collaborator
|
Thanks, this is a real bug: the global random.seed() let concurrent byte requests change each other's output. Verified locally: all 130 tests pass, and both new tests fail without the fix. Merging. |
Contributor
Author
|
Thank you for reproducing it locally and merging, much appreciated! |
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.
A seeded /stream-bytes response currently uses the process-wide random generator. If another byte request runs between chunks, it reseeds or advances that generator and changes the remainder of the first response, even though its seed is unchanged.
Give /bytes and /stream-bytes their own random.Random instance for each request. The streaming closure retains that instance, so interleaved responses remain independent. Existing seeded byte sequences, size limits and chunk boundaries are preserved.
The two regression tests use real unbuffered Flask response iterators, without threads or RNG mocks. They cover a stream interrupted by a /bytes request and two interleaved streams with different chunk sizes. Both fail on the original implementation; the two existing seed controls still pass. All four pass with the fix.
Validation on Windows:
The full runs emit an existing unclosed-iterator assertion from the WSGI validator test. The unmodified base reproduces that assertion while passing its 128 tests. Docker, native Linux, remote target-URL tests, and Python 3.12–3.14 were not run. The new iterator tests use the existing local_only marker because the remote test client eagerly consumes responses.
This was found through source inspection and reproduced locally. AI assistance: OpenAI Codex investigated, implemented and validated this change.