Repository navigation
Conversation
aiohttp's ClientWebSocketResponse.close() swallows a transport error while waiting for the peer's close frame, stamps ABNORMAL_CLOSURE (1006) and returns normally. _close_socket took that as an acknowledged close, so close_unacked under-counted and 1006 leaked into close_codes. 1006 is never sent on the wire (RFC 6455 7.4.1), so treat it as the unanswered close it is. This is what made test_teardown_time_is_not_counted_as_load flaky on macOS/3.10 (close_unacked == 0). Signed-off-by: kurok <22548029+kurok@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the flaky
test_teardown_time_is_not_counted_as_loadfailure seen on macOS / Python 3.10 in #300 (AssertionError: 0 not greater than or equal to 1onclose_unacked). The flaky test was exposing a real bug in how closes are counted.Root cause
aiohttp's
ClientWebSocketResponse.close()(3.14.5) catches any exception it hits while waiting for the peer's CLOSE frame. It then setsclose_code = WSCloseCode.ABNORMAL_CLOSURE(1006) and returns normally._close_socketonly countedclose_unackedwhenclose()raised, so a close the server never answered was counted as acknowledged and1006was added toclose_codes.RFC 6455 §7.4.1 says 1006 is never sent in a close frame. So it always means no close frame came back, and counting it as unacknowledged is the correct reading.
Change
_close_socket: afterclose()returns, a1006close code counts towardclose_unackedand is not added toclose_codes.TestCloseSocketunit tests use a fake socket, so they don't depend on reproducing the race. The 1006 test fails onmainand passes with this fix.Testing
ruff format,ruff checkandmypyare clean