Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace shared global _empty_stream with separate instances #1340

merged 1 commit into from Aug 4, 2018


Copy link

@chromakode chromakode commented Aug 3, 2018

The use of a shared _empty_stream instance can cause subtle failures when a test or process closes the shared stream.

For example, if a test initializes a request with a file upload FileStorage with a falsy stream argument, the FileStorage will use the shared _empty_stream: = stream or _empty_stream

When the request is torn down, it will close the shared _empty_stream:


Subsequently, if a test environment is created with no specified input_stream, it will use the closed _empty_stream:

input_stream = _empty_stream

Now calls to request.get_data() and other operations on the stream will fail.

In the case where we discovered this behavior at Patreon, two unrelated tests were causing a failure: one which initialized an FileStorage with _empty_stream, and one which called request.get_data().

I believe that replacing this shared instance with individually created BytesIO buffers would reduce the chances of such spooky shared global bugs without creating much overhead. What do you think?

Copy link

davidism commented Aug 3, 2018

Makes sense. Would you add a changelog entry?

@chromakode chromakode force-pushed the remove-shared-empty-stream branch 2 times, most recently from 6e3e3e4 to 0d23117 Compare August 3, 2018 20:51
If a test closed the _empty_stream, subsequent requests could reuse this
closed stream, causing request.get_data() and other methods to fail.
Copy link
Contributor Author

Thanks @davidism. I've amended the commit with a changelog entry and the commit is now passing lint.

@davidism davidism merged commit 8c4e6b5 into pallets:master Aug 4, 2018
Copy link

davidism commented Aug 4, 2018


@chromakode chromakode deleted the remove-shared-empty-stream branch August 4, 2018 00:31
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants