Skip to content

fix(client): avoid cross-loop eager body writers - #13359

Open
daleselaji-dev wants to merge 1 commit into
aio-libs:masterfrom
daleselaji-dev:codex/fix-cross-loop-eager-write
Open

fix(client): avoid cross-loop eager body writers#13359
daleselaji-dev wants to merge 1 commit into
aio-libs:masterfrom
daleselaji-dev:codex/fix-cross-loop-eager-write

Conversation

@daleselaji-dev

Copy link
Copy Markdown

What do these changes do?

Guard aiohttp's Python 3.12+ eager request-body writer optimization so it is used only when the request is sent from the session's event loop. Cross-loop use now schedules the writer on the session loop instead of eagerly stepping a coroutine from the caller's thread.

Are there changes in behavior for the user?

Same-loop requests keep the existing eager-write optimization. Cross-loop misuse no longer lets a foreign thread execute a task against the session loop, avoiding the event-loop corruption described in #13346.

Related issue number

Fixes #13346

Testing

  • Added a regression test asserting that the eager task constructor is not used when the caller loop differs.
  • python -m compileall -q aiohttp/client_reqrep.py tests/test_client_request.py passed.
  • The focused pytest run was blocked locally because the Windows checkout cannot build aiohttp's generated C extensions; GitHub CI will provide the supported build/test environment.
  • Added CHANGES/13346.bugfix.rst.

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Aug 9, 2026
@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.99%. Comparing base (288cf46) to head (47ca267).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #13359   +/-   ##
=======================================
  Coverage   98.99%   98.99%           
=======================================
  Files         132      132           
  Lines       49156    49164    +8     
  Branches     2560     2560           
=======================================
+ Hits        48661    48669    +8     
  Misses        371      371           
  Partials      124      124           
Flag Coverage Δ
Autobahn 22.10% <11.11%> (-0.01%) ⬇️
CI-GHA 98.90% <100.00%> (+<0.01%) ⬆️
OS-Linux 98.67% <100.00%> (+<0.01%) ⬆️
OS-Windows 97.03% <100.00%> (+<0.01%) ⬆️
OS-macOS 97.93% <100.00%> (+<0.01%) ⬆️
Py-3.10 98.12% <88.88%> (+<0.01%) ⬆️
Py-3.11 98.37% <88.88%> (-0.01%) ⬇️
Py-3.12 98.47% <100.00%> (+<0.01%) ⬆️
Py-3.13 98.45% <100.00%> (+<0.01%) ⬆️
Py-3.14 98.46% <100.00%> (-0.01%) ⬇️
Py-3.14t 97.56% <100.00%> (-0.01%) ⬇️
Py-pypy-3.11 97.40% <88.88%> (-0.02%) ⬇️
VM-macos 97.93% <100.00%> (+<0.01%) ⬆️
VM-ubuntu 98.67% <100.00%> (+<0.01%) ⬆️
VM-windows 97.03% <100.00%> (+<0.01%) ⬆️
cython-coverage 38.06% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@codspeed-hq

codspeed-hq Bot commented Aug 9, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 84 untouched benchmarks
⏩ 83 skipped benchmarks1


Comparing daleselaji-dev:codex/fix-cross-loop-eager-write (47ca267) with master (288cf46)

Open in CodSpeed

Footnotes

  1. 83 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Eager write_bytes task makes cross-loop ClientSession use silently corrupt the session's event loop on Python 3.12/3.13

1 participant