Commit 93a6f79
Cut BaseProtocol circular reference on close. (#1049)
A bound method contains a reference to the instance it's bound to.
Most of the time, bound methods are created lazily at access time by
the descriptor protocol and discarded after calling. But saving a bound
method as another attribute on the instance creates a long-lived cycle,
here `.timeout_callback.__self__`, that needs to be explicitly broken
if we don't want to wake up python's garbage collector to do it.
Without this change, the new assertion in the tests would fail, and
`pytest --pdb` would show the bound methods `_on_timeout` and
`_on_waiter_completed` at the end of `p gc.get_referrers(protoref())`.
[Also, unset `transport` in `Protocol.abort()` to break another cycle]
Co-authored-by: Elvis Pranskevichus <elvis@edgedb.com>1 parent ca9f03b commit 93a6f79
File tree
3 files changed
+25
-14
lines changed- asyncpg/protocol
- tests
3 files changed
+25
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
43 | | - | |
44 | 42 | | |
45 | 43 | | |
46 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
102 | | - | |
103 | 101 | | |
104 | 102 | | |
105 | 103 | | |
| |||
607 | 605 | | |
608 | 606 | | |
609 | 607 | | |
| 608 | + | |
610 | 609 | | |
611 | 610 | | |
612 | 611 | | |
| |||
777 | 776 | | |
778 | 777 | | |
779 | 778 | | |
780 | | - | |
781 | | - | |
| 779 | + | |
| 780 | + | |
782 | 781 | | |
783 | 782 | | |
784 | 783 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
1846 | 1847 | | |
1847 | 1848 | | |
1848 | 1849 | | |
1849 | | - | |
1850 | | - | |
1851 | | - | |
1852 | | - | |
1853 | | - | |
1854 | | - | |
1855 | | - | |
1856 | | - | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
1857 | 1871 | | |
1858 | 1872 | | |
1859 | 1873 | | |
| |||
0 commit comments