Enable immediate garbage collection of connections. - #1752
Merged
Conversation
aaugustin
force-pushed
the
break-reference-cycle
branch
4 times, most recently
from
August 24, 2026 12:33
6e7c9a7 to
6e08680
Compare
There was a problem hiding this comment.
Pull request overview
Enables closed connections to be reclaimed immediately without cyclic GC.
Changes:
- Replaces logger backreferences with weak proxies.
- Clears cancelled keepalive task references.
- Adds regression tests and changelog documentation.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/websockets/asyncio/connection.py |
Breaks logger and keepalive cycles. |
src/websockets/sync/connection.py |
Weakens the logger backreference. |
src/websockets/trio/connection.py |
Weakens the logger backreference. |
src/websockets/legacy/protocol.py |
Breaks logger and keepalive cycles. |
tests/asyncio/test_connection.py |
Adds collection coverage and updates keepalive tests. |
tests/sync/test_connection.py |
Adds collection coverage. |
tests/trio/test_connection.py |
Adds collection coverage. |
tests/legacy/test_protocol.py |
Preserves task references for assertions. |
docs/project/changelog.rst |
Documents immediate collection. |
Suppressed comments (1)
tests/asyncio/test_connection.py:1354
- Calling
gc.collect()manually still runs cyclic collection even while automatic GC is disabled, so this test passes with the original reference cycle and doesn't verify immediate reference-counted cleanup. Assert the weak reference immediately after deletion instead.
gc.collect()
self.assertIsNone(connection_ref(), "still alive after garbage collection")
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
aaugustin
force-pushed
the
break-reference-cycle
branch
3 times, most recently
from
August 25, 2026 06:52
24df5d6 to
09acb90
Compare
While the legacy implementation is in maintenance mode at this point, the change looked simple and safe enough to update it as well. Fix #1749.
aaugustin
force-pushed
the
break-reference-cycle
branch
from
August 25, 2026 06:52
09acb90 to
50683fe
Compare
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.
While the legacy implementation is in maintenance mode at this point,
the change looked simple and safe enough to update it as well.
Fix #1749.