Skip to content

Revert empty context for ASGI runs#2911

Merged
Kludex merged 1 commit intomainfrom
revert-2742
Apr 21, 2026
Merged

Revert empty context for ASGI runs#2911
Kludex merged 1 commit intomainfrom
revert-2742

Conversation

@Kludex
Copy link
Copy Markdown
Owner

@Kludex Kludex commented Apr 21, 2026

Summary

Reverts #2742 and #2859, which made each ASGI request run in a fresh contextvars.Context to work around python/cpython#140947.

The workaround broke valid use cases that the original discussion did not anticipate:

A follow-up PR will reintroduce the behavior as an opt-in flag so users who rely on the isolation can still get it.

Test plan

  • uv run ruff check .
  • uv run ruff format --check .
  • uv run mypy uvicorn
  • uv run pytest tests/test_server.py tests/protocols/test_http.py

AI Disclaimer

This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.

This reverts PRs #2742 and #2859 which made each ASGI request run in a
fresh contextvars.Context to work around python/cpython#140947.

The workaround broke valid use cases: context set in the lifespan or by
external instrumentation (e.g. OpenTelemetry eBPF context propagation)
is hidden from ASGI handlers. A follow-up PR will reintroduce the
behavior as an opt-in flag.
@github-actions
Copy link
Copy Markdown
Contributor

📖 Docs preview: https://8405f61d.uvicorn.pages.dev

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 21, 2026

Merging this PR will degrade performance by 11.23%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 23 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
test_bench_fragmented_body[httptools] 2.2 ms 2.4 ms -11.23%

Comparing revert-2742 (551589f) with main (850d926)

Open in CodSpeed

@Kludex Kludex merged commit 45c0b56 into main Apr 21, 2026
23 of 24 checks passed
@Kludex Kludex deleted the revert-2742 branch April 21, 2026 08:51
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.

1 participant