Repository navigation
Close leaked sqlite3 connections (ResourceWarning on Python 3.13+) - #6181
Merged
stamparm merged 1 commit intoNov 12, 2026
Merged
Conversation
Python 3.13+ reports sqlite3 connections that are garbage collected without being closed. The unit tests print a run of "ResourceWarning: unclosed database" lines on Linux/CPython 3.14: - SQLAlchemy.close() only returned its connection to the engine's pool, so the underlying DBAPI connection (e.g. sqlite3 for '-d sqlite://...') stayed open. Dispose the engine on close. - vulnTest() used "with sqlite3.connect(...)", which commits but does not close the connection. Use contextlib.closing(). - test_multibit and test_sqlalchemy never closed what they opened. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
On Python 3.13+, sqlite3 warns when a connection is garbage collected without being closed. Running the unit tests on Linux with CPython 3.14 prints more than 20
ResourceWarning: unclosed databaselines. CI only runs 3.14 on Windows, so they don't show up there.Most of the warnings come from the tests, but one is a real leak in sqlmap itself:
lib/utils/sqlalchemy.py:SQLAlchemy.close()(inherited from the generic connector) only returns the connection to the engine's pool. The underlying DBAPI connection stays open, for example the sqlite3 connection with-d sqlite://....close()now also disposes the engine.lib/core/testing.py:vulnTest()usedwith sqlite3.connect(...). sqlite3's context manager commits but does not close, so it now usescontextlib.closing()with an explicit commit.tests/test_multibit.py,tests/test_sqlalchemy.py: close the connections the tests open.Proof
Linux, CPython 3.14.7,
python3 -B -W always::ResourceWarning -m unittest discover -s tests -p "test_*.py":Ran 2751 tests ... OK (skipped=10), with 20+unclosed databasewarningsRan 2751 tests ... OK (skipped=10), with nounclosed databasewarningsThe
sqlalchemy.pychange is what fixes the connector leak, not just the test cleanup. With only that file reverted,tests.test_sqlalchemystill warns even though the test callssa.close():python3 -W always::ResourceWarning sqlmap.py --vuln-test(which runs the changedvulnTest()code) ends withvuln test final result: PASSEDand nounclosed databasewarnings.