Skip to content

fix(runtime-sdk): fix contextvars not being shared in WSGI streaming response - #288

Merged
ryanking13 merged 3 commits into
mainfrom
gyeongjae/flask-stream
Nov 4, 2026
Merged

ryanking13 merged 3 commits into
mainfrom
gyeongjae/flask-stream

Conversation

@ryanking13

Copy link
Copy Markdown
Contributor

fix #287

WSGI streaming response use stack switching. However, they should use the same contextvars, since they are in the same request context.

@ask-bonk

ask-bonk Bot commented Oct 7, 2026

Copy link
Copy Markdown

LGTM

github run

@clanky-the-clanker

clanky-the-clanker Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

This pull request's reviews are posted as pull request reviews: see the review of 0f1d4e8d.

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved — No issues found: the fix runs the app call, iteration and close in one shared request context, and new tests cover sharing within a stream, isolation between streams and reset on cancel.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security concerns.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md updates needed.


📋 Code Quality: ✅ LGTM

No issues found.

  • wsgi.py: one copied contextvars.Context covers the app call, iter(result), every next() and close(). App-set values stay visible during streaming, and tokens reset in the context that created them.
  • Cleanup: the try/finally in close_all closes wsgi.input even if closing the iterable raises.
  • Tests: the workerd WSGI tests cover sharing within a stream, isolation between concurrent streams, and token reset on cancel. The Flask tests exercise stream_with_context.

⚡ Performance: ✅ LGTM

No performance concerns. Running each chunk through context.run adds very little overhead.


📝 Documentation: ✅ LGTM

No documentation issues.


Reviewed commit: 0f1d4e8d

@ryanking13
ryanking13 merged commit 7cc6cbd into main Nov 4, 2026
20 checks passed
@ryanking13
ryanking13 deleted the gyeongjae/flask-stream branch November 4, 2026 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

runtime-sdk: Flask stream_with_context fails across WSGI streaming callback contexts

3 participants