Skip to content

Fix WebSocketResponse.prepared not correctly reflect the WebSocket's prepared state #10971

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

Merged
merged 9 commits into from
May 23, 2025

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented May 23, 2025

This PR fixes an issue where the WebSocketResponse.prepared property did not correctly reflect the WebSocket's prepared state, particularly during timeout scenarios.

Previously, the prepared property inherited from StreamResponse only checked for _payload_writer, but in WebSocket timeout scenarios, the _writer could be set while _payload_writer remained None, leading to incorrect state reporting.

Changes

  • Added an explicit prepared property to WebSocketResponse that checks for _writer instead of relying on the parent class's _payload_writer check
  • Added a check in the prepare() method to prevent double preparation when _writer is already set
  • Added comprehensive tests covering timeout scenarios and edge cases where WebSocket state needs to be correctly tracked

fixes #6009

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label May 23, 2025
@bdraco bdraco added backport-3.11 Trigger automatic backporting to the 3.11 release branch by Patchback robot backport-3.12 Trigger automatic backporting to the 3.12 release branch by Patchback robot labels May 23, 2025
@bdraco bdraco changed the title Fix websocket prepare Fix WebSocketResponse.prepared` not correctly reflect the WebSocket's prepared state May 23, 2025
@bdraco bdraco changed the title Fix WebSocketResponse.prepared` not correctly reflect the WebSocket's prepared state Fix WebSocketResponse.prepared not correctly reflect the WebSocket's prepared state May 23, 2025
Copy link

codecov bot commented May 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.77%. Comparing base (1878509) to head (2cb4df5).
Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10971      +/-   ##
==========================================
+ Coverage   98.10%   98.77%   +0.66%     
==========================================
  Files         129      129              
  Lines       39541    39620      +79     
  Branches     2185     2186       +1     
==========================================
+ Hits        38792    39133     +341     
+ Misses        591      339     -252     
+ Partials      158      148      -10     
Flag Coverage Δ
CI-GHA 98.65% <100.00%> (+0.65%) ⬆️
OS-Linux 98.36% <100.00%> (+0.66%) ⬆️
OS-Windows 96.54% <100.00%> (+0.54%) ⬆️
OS-macOS 97.51% <100.00%> (-0.01%) ⬇️
Py-3.10.11 97.40% <100.00%> (+0.29%) ⬆️
Py-3.10.17 97.93% <100.00%> (+0.63%) ⬆️
Py-3.11.12 98.02% <100.00%> (?)
Py-3.11.9 97.48% <100.00%> (+0.29%) ⬆️
Py-3.12.10 98.42% <100.00%> (+0.93%) ⬆️
Py-3.13.3 98.40% <100.00%> (+1.10%) ⬆️
Py-3.9.13 97.28% <100.00%> (+<0.01%) ⬆️
Py-3.9.22 97.80% <100.00%> (+0.66%) ⬆️
Py-pypy7.3.16 84.87% <9.23%> (?)
VM-macos 97.51% <100.00%> (-0.01%) ⬇️
VM-ubuntu 98.36% <100.00%> (+0.66%) ⬆️
VM-windows 96.54% <100.00%> (+0.54%) ⬆️

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

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

Copy link

codspeed-hq bot commented May 23, 2025

CodSpeed Performance Report

Merging #10971 will not alter performance

Comparing fix_6009 (2cb4df5) with master (48f5324)

Summary

✅ 59 untouched benchmarks

@bdraco bdraco marked this pull request as ready for review May 23, 2025 18:50
@bdraco bdraco requested review from webknjaz and asvetlov as code owners May 23, 2025 18:50
@bdraco bdraco merged commit 1ee187c into master May 23, 2025
40 checks passed
@bdraco bdraco deleted the fix_6009 branch May 23, 2025 18:59
Copy link
Contributor

patchback bot commented May 23, 2025

Backport to 3.11: 💚 backport PR created

✅ Backport PR branch: patchback/backports/3.11/1ee187c08c9bb59acb53e1c80a06c79a4183de10/pr-10971

Backported as #10982

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

Copy link
Contributor

patchback bot commented May 23, 2025

Backport to 3.12: 💚 backport PR created

✅ Backport PR branch: patchback/backports/3.12/1ee187c08c9bb59acb53e1c80a06c79a4183de10/pr-10971

Backported as #10983

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

patchback bot pushed a commit that referenced this pull request May 23, 2025
bdraco added a commit that referenced this pull request May 23, 2025
…not correctly reflect the WebSocket's prepared state (#10982)

Co-authored-by: J. Nick Koston <[email protected]>
fixes #6009
bdraco added a commit that referenced this pull request May 23, 2025
…not correctly reflect the WebSocket's prepared state (#10983)

Co-authored-by: J. Nick Koston <[email protected]>
fixes #6009
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-3.11 Trigger automatic backporting to the 3.11 release branch by Patchback robot backport-3.12 Trigger automatic backporting to the 3.12 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.

WebSocket prepare property incorrectly reflects prepared state
1 participant