Skip to content

Fix compressed body corruption after a cancelled write - #14479

Merged
Dreamsorcerer merged 6 commits into
masterfrom
bot-cancelled-compressed-write
Nov 27, 2026
Merged

Dreamsorcerer merged 6 commits into
masterfrom
bot-cancelled-compressed-write

Conversation

@Dreamsorcerer

@Dreamsorcerer Dreamsorcerer commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

No description provided.

@codspeed

codspeed Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 50 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 102 untouched benchmarks
⏩ 83 skipped benchmarks1


Comparing bot-cancelled-compressed-write (0bfeca0) with master (5d49a2b)

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. ↩

Comment thread tests/test_http_writer.py Resolved
Comment thread tests/test_http_writer.py Resolved
Comment thread tests/test_web_server.py Resolved
Comment thread CHANGES/14479.bugfix.rst Resolved
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Nov 27, 2026
@Dreamsorcerer Dreamsorcerer changed the title [bot] Fix compressed body corruption after a cancelled write Fix compressed body corruption after a cancelled write Nov 27, 2026
@Dreamsorcerer
Dreamsorcerer marked this pull request as ready for review November 27, 2026 01:57
@Dreamsorcerer Dreamsorcerer added backport-3.14 Trigger automatic backporting to the 3.14 release branch by Patchback robot backport-3.15 Trigger automatic backporting to the 3.15 release branch by Patchback robot labels Nov 27, 2026
@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

security Security Review

This PR appears safe to merge from a security standpoint.

What was checked
  • Both compressed write paths (write() and write_eof()) now record cancellation and refuse to continue, so a cancelled compress can no longer produce a complete-looking body with corrupted contents.
  • All body-writing paths in the library (payload writers, multipart, FileResponse, client request writer) go through these two guarded methods, and set_eof() is only called on a no-body path where compression never ran.
  • The new guard closes the transport and raises an exception the server and client error paths already catch as a disconnect, so the connection is never reused and the peer sees a detectably truncated message instead of corrupt data.
  • A cancellation delivered before the executor thread starts also sets the flag and closes the connection; that is over-conservative in the safe direction and does not weaken anything.

@codecov

codecov Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.12%. Comparing base (7efff04) to head (0bfeca0).
⚠️ Report is 5 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff            @@
##           master   #14479    +/-   ##
========================================
  Coverage   99.11%   99.12%            
========================================
  Files         135      135            
  Lines       53868    54123   +255     
  Branches     2760     2778    +18     
========================================
+ Hits        53393    53648   +255     
  Misses        359      359            
  Partials      116      116            
Flag Coverage Δ
Autobahn 21.62% <14.28%> (-0.01%) ⬇️
CI-GHA 99.05% <100.00%> (+<0.01%) ⬆️
OS-Linux 98.73% <100.00%> (+<0.01%) ⬆️
OS-Windows 97.49% <100.00%> (+0.01%) ⬆️
OS-macOS 98.35% <100.00%> (+<0.01%) ⬆️
Py-3.11 98.29% <100.00%> (+<0.01%) ⬆️
Py-3.12 98.38% <100.00%> (+<0.01%) ⬆️
Py-3.13 98.37% <100.00%> (+<0.01%) ⬆️
Py-3.14 98.43% <100.00%> (+<0.01%) ⬆️
Py-3.15 98.43% <100.00%> (+0.01%) ⬆️
Py-3.15t 98.29% <100.00%> (+0.01%) ⬆️
Py-pypy-3.12 96.97% <100.00%> (+<0.01%) ⬆️
VM-macos-latest 98.35% <100.00%> (+<0.01%) ⬆️
VM-ubuntu-latest 98.73% <100.00%> (+<0.01%) ⬆️
VM-windows-latest 97.49% <100.00%> (+0.01%) ⬆️
cython-coverage 83.90% <100.00%> (+0.13%) ⬆️

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.

@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no new issues were found.RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

[Medium impact] The PR appears safe to merge; no new issues were found.

Reviews (3) · Last reviewed commit: "Update tests/test_http_writer.py" · Reviewed by Greptile

Comment thread tests/test_http_writer.py Resolved
@Dreamsorcerer
Dreamsorcerer merged commit 9df7b2b into master Nov 27, 2026
54 checks passed
@Dreamsorcerer
Dreamsorcerer deleted the bot-cancelled-compressed-write branch November 27, 2026 02:26
@patchback

patchback Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Backport to 3.15: 💔 cherry-picking failed — conflicts found

❌ Failed to cleanly apply 9df7b2b on top of patchback/backports/3.15/9df7b2bc19f86a76283871b2ef5b5f99861b1ea0/pr-14479

Backporting merged PR #14479 into master

  1. Ensure you have a local repo clone of your fork. Unless you cloned it
    from the upstream, this would be your origin remote.
  2. Make sure you have an upstream repo added as a remote too. In these
    instructions you'll refer to it by the name upstream. If you don't
    have it, here's how you can add it:
    git remote add upstream https://github.com/aio-libs/aiohttp.git
    
  3. Ensure you have the latest copy of upstream and prepare a branch
    that will hold the backported code:
    git fetch upstream
    git checkout -b patchback/backports/3.15/9df7b2bc19f86a76283871b2ef5b5f99861b1ea0/pr-14479 upstream/3.15
    
  4. Now, cherry-pick PR Fix compressed body corruption after a cancelled write #14479 contents into that branch:
    git cherry-pick -x 9df7b2bc19f86a76283871b2ef5b5f99861b1ea0
    
    If it'll yell at you with something like fatal: Commit 9df7b2bc19f86a76283871b2ef5b5f99861b1ea0 is a merge but no -m option was given., add -m 1 as follows instead:
    git cherry-pick -m1 -x 9df7b2bc19f86a76283871b2ef5b5f99861b1ea0
    
  5. At this point, you'll encounter some merge conflicts. You must
    resolve them in order to preserve the patch from PR Fix compressed body corruption after a cancelled write #14479 as close to the
    original as possible.
  6. Once conflicts are resolved and git added, run:
    git cherry-pick --continue
    
  7. Push this branch to your fork on GitHub:
    git push origin patchback/backports/3.15/9df7b2bc19f86a76283871b2ef5b5f99861b1ea0/pr-14479
    
  8. Create a PR, ensure that the CI is green. If it's not — update it so that
    the tests and any other checks pass. This is it!
    Now relax and wait for the maintainers to process your pull request
    when they have some cycles to do reviews. Don't worry — they'll tell you if
    any improvements are necessary when the time comes!

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@patchback

patchback Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Backport to 3.14: 💔 cherry-picking failed — conflicts found

❌ Failed to cleanly apply 9df7b2b on top of patchback/backports/3.14/9df7b2bc19f86a76283871b2ef5b5f99861b1ea0/pr-14479

Backporting merged PR #14479 into master

  1. Ensure you have a local repo clone of your fork. Unless you cloned it
    from the upstream, this would be your origin remote.
  2. Make sure you have an upstream repo added as a remote too. In these
    instructions you'll refer to it by the name upstream. If you don't
    have it, here's how you can add it:
    git remote add upstream https://github.com/aio-libs/aiohttp.git
    
  3. Ensure you have the latest copy of upstream and prepare a branch
    that will hold the backported code:
    git fetch upstream
    git checkout -b patchback/backports/3.14/9df7b2bc19f86a76283871b2ef5b5f99861b1ea0/pr-14479 upstream/3.14
    
  4. Now, cherry-pick PR Fix compressed body corruption after a cancelled write #14479 contents into that branch:
    git cherry-pick -x 9df7b2bc19f86a76283871b2ef5b5f99861b1ea0
    
    If it'll yell at you with something like fatal: Commit 9df7b2bc19f86a76283871b2ef5b5f99861b1ea0 is a merge but no -m option was given., add -m 1 as follows instead:
    git cherry-pick -m1 -x 9df7b2bc19f86a76283871b2ef5b5f99861b1ea0
    
  5. At this point, you'll encounter some merge conflicts. You must
    resolve them in order to preserve the patch from PR Fix compressed body corruption after a cancelled write #14479 as close to the
    original as possible.
  6. Once conflicts are resolved and git added, run:
    git cherry-pick --continue
    
  7. Push this branch to your fork on GitHub:
    git push origin patchback/backports/3.14/9df7b2bc19f86a76283871b2ef5b5f99861b1ea0/pr-14479
    
  8. Create a PR, ensure that the CI is green. If it's not — update it so that
    the tests and any other checks pass. This is it!
    Now relax and wait for the maintainers to process your pull request
    when they have some cycles to do reviews. Don't worry — they'll tell you if
    any improvements are necessary when the time comes!

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

Dreamsorcerer added a commit that referenced this pull request Nov 27, 2026
Dreamsorcerer added a commit that referenced this pull request Nov 27, 2026
…ter a cancelled write (#14479) (#14493)

(cherry picked from commit 9df7b2b)
(cherry picked from commit 83fc669)

Co-authored-by: Sam Bull <git@sambull.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-3.14 Trigger automatic backporting to the 3.14 release branch by Patchback robot backport-3.15 Trigger automatic backporting to the 3.15 release branch by Patchback robot 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.

1 participant