Commit 52ada4d
Fix file descriptor leak when SQLite3 objects are garbage collected
Summary:
The SQLite3 native data classes were registered with NO_SWEEP flag, which
prevented their sweep methods from being called during request shutdown.
This caused file descriptors to leak when PHP code didn't explicitly
call $db->close() and the objects survived until request end.
Observed this in prod when comparing PDO and SQLite file descriptor usage
https://www.internalfb.com/phabricator/paste/view/P2169381411
# This Change
1. Adds sweep() methods to SQLite3, SQLite3Stmt, and SQLite3Result that
properly clean up native SQLite resources
2. Updates destructors to call sweep() for consistent cleanup
3. Removes the NO_SWEEP flag so sweep is called during request shutdown
The sweep() implementation follows the same pattern used by PDO SQLite,
including proper handling of UDF Variants with releaseForSweep().
# Why NO_SWEEP was wrong
NO_SWEEP doesn't defer cleanup - it PREVENTS cleanup entirely for objects
that survive until request end. The memory is bulk-freed without calling
any cleanup functions, so native resources (file descriptors) leak.
Reviewed By: paulbiss
Differential Revision: D92496862
fbshipit-source-id: 5ed26749e770cc99c845b9b5741d9b4ab12b75a61 parent 8ef8458 commit 52ada4d
2 files changed
Lines changed: 10 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
170 | | - | |
| 170 | + | |
171 | 171 | | |
172 | 172 | | |
| 173 | + | |
173 | 174 | | |
174 | 175 | | |
175 | 176 | | |
| |||
485 | 486 | | |
486 | 487 | | |
487 | 488 | | |
488 | | - | |
| 489 | + | |
489 | 490 | | |
490 | 491 | | |
| 492 | + | |
491 | 493 | | |
492 | 494 | | |
493 | 495 | | |
| |||
774 | 776 | | |
775 | 777 | | |
776 | 778 | | |
777 | | - | |
| 779 | + | |
778 | 780 | | |
779 | 781 | | |
780 | 782 | | |
| |||
783 | 785 | | |
784 | 786 | | |
785 | 787 | | |
786 | | - | |
| 788 | + | |
787 | 789 | | |
788 | 790 | | |
789 | 791 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
54 | | - | |
| 55 | + | |
| 56 | + | |
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
| |||
0 commit comments