Commit eb69460
committed
gh-145040: Prevent closing sqlite3 connection from within a callback
Instead of detecting a closed connection after the damage has been done,
prevent Connection.close() from succeeding while a SQLite callback is
executing. This aligns with the SQLite C API docs, which state that
applications must not close the database connection from within a
callback.
Add an in_callback counter to the connection object, incremented before
stmt_step() and decremented after. If close() is called while the
counter is positive, ProgrammingError is raised and the database
connection remains open. A counter (rather than a boolean flag) is used
to correctly handle nested callbacks.
Also convert test docstrings to comments per reviewer feedback, and add
a test for the nested callback scenario.1 parent c7dbc7e commit eb69460
File tree
4 files changed
+59
-7
lines changed- Lib/test/test_sqlite3
- Modules/_sqlite
4 files changed
+59
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
588 | 588 | | |
589 | 589 | | |
590 | 590 | | |
591 | | - | |
| 591 | + | |
592 | 592 | | |
593 | 593 | | |
594 | 594 | | |
| |||
751 | 751 | | |
752 | 752 | | |
753 | 753 | | |
754 | | - | |
| 754 | + | |
755 | 755 | | |
756 | 756 | | |
757 | 757 | | |
| |||
774 | 774 | | |
775 | 775 | | |
776 | 776 | | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
777 | 800 | | |
778 | | - | |
| 801 | + | |
779 | 802 | | |
780 | 803 | | |
781 | 804 | | |
| |||
790 | 813 | | |
791 | 814 | | |
792 | 815 | | |
793 | | - | |
| 816 | + | |
794 | 817 | | |
795 | 818 | | |
796 | 819 | | |
| |||
817 | 840 | | |
818 | 841 | | |
819 | 842 | | |
820 | | - | |
| 843 | + | |
821 | 844 | | |
822 | 845 | | |
823 | 846 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
| 305 | + | |
| 306 | + | |
305 | 307 | | |
306 | 308 | | |
307 | 309 | | |
| |||
655 | 657 | | |
656 | 658 | | |
657 | 659 | | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
658 | 670 | | |
659 | 671 | | |
660 | 672 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
68 | 77 | | |
69 | 78 | | |
70 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
905 | 905 | | |
906 | 906 | | |
907 | 907 | | |
| 908 | + | |
908 | 909 | | |
909 | | - | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
910 | 914 | | |
911 | 915 | | |
912 | 916 | | |
| |||
1161 | 1165 | | |
1162 | 1166 | | |
1163 | 1167 | | |
| 1168 | + | |
1164 | 1169 | | |
1165 | | - | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
1166 | 1173 | | |
1167 | 1174 | | |
| 1175 | + | |
1168 | 1176 | | |
1169 | 1177 | | |
1170 | 1178 | | |
| |||
0 commit comments