Commit 9274d15
committed
Fix automatic cleanup of cursors and statements
Current coding for automatic collection and closure of cursors and
statements is using a callback through a weakref, but stores this
weakref _inside_ the tracked object, thus making the weakref part of a
potential reference cycle. Per Python spec, the callback will only be
invoked if the weakref is still alive, which will not be the case if a
cursor or a statement were part of a reference cycle. This leads to a
failure to close the cursor on database side and a subsequent
DuplicateCursorError if the id got reused for another cursor.
This is easily fixed by storing the weakref alongside the cursor and
statement garbage lists.1 parent 4dd74f1 commit 9274d15
2 files changed
Lines changed: 31 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
618 | 618 | | |
619 | 619 | | |
620 | 620 | | |
621 | | - | |
622 | | - | |
623 | | - | |
624 | | - | |
| 621 | + | |
625 | 622 | | |
626 | 623 | | |
627 | 624 | | |
| |||
630 | 627 | | |
631 | 628 | | |
632 | 629 | | |
633 | | - | |
| 630 | + | |
634 | 631 | | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | 632 | | |
639 | 633 | | |
640 | 634 | | |
| |||
1280 | 1274 | | |
1281 | 1275 | | |
1282 | 1276 | | |
1283 | | - | |
1284 | | - | |
1285 | | - | |
1286 | | - | |
| 1277 | + | |
| 1278 | + | |
1287 | 1279 | | |
1288 | 1280 | | |
1289 | 1281 | | |
| |||
1424 | 1416 | | |
1425 | 1417 | | |
1426 | 1418 | | |
1427 | | - | |
| 1419 | + | |
1428 | 1420 | | |
1429 | | - | |
1430 | | - | |
1431 | | - | |
1432 | 1421 | | |
1433 | 1422 | | |
1434 | 1423 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
473 | 474 | | |
474 | 475 | | |
475 | 476 | | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
476 | 499 | | |
477 | 500 | | |
478 | 501 | | |
| |||
501 | 524 | | |
502 | 525 | | |
503 | 526 | | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
504 | 530 | | |
505 | 531 | | |
506 | 532 | | |
| |||
0 commit comments