Explicitly close DB connections when discarding SQLAlchemy's Engine#6303
Merged
sawa3030 merged 1 commit intooptuna:masterfrom Oct 17, 2025
Merged
Explicitly close DB connections when discarding SQLAlchemy's Engine#6303sawa3030 merged 1 commit intooptuna:masterfrom
Engine#6303sawa3030 merged 1 commit intooptuna:masterfrom
Conversation
Member
c-bata
approved these changes
Oct 17, 2025
Member
c-bata
left a comment
There was a problem hiding this comment.
Changes themselves look good to me.
According to the Python 3.13 release note, the sqlite3 module started emitting ResourceWarning from version 3.13. Some failed tests such as this workflow run and this one are using Python 3.13.
A ResourceWarning is now emitted if a Connection object is not closed explicitly. (Contributed by Erlend E. Aasland in gh-105539.)
https://docs.python.org/3/whatsnew/3.13.html#sqlite3
However, following recent workflow runs uses Python 3.8 or 3.12, so I would say we still need to investigate those errors.
- https://github.com/optuna/optuna/actions/runs/18488888348/job/52677711048?pr=6300
- https://github.com/optuna/optuna/actions/runs/18512431531/job/52756077902
Anyway, thank you for your pull request. LGTM.
This was referenced Nov 7, 2025
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.
Motivation
Recently, random failures in CI have been occurring frequently (e.g., #5797 (comment)). This may be caused by connection objects created by SQLAlchemy not being properly released (see https://docs.sqlalchemy.org/en/20/core/connections.html#engine-disposal).
To call
Engine.dispose()after each unit test will resolve this issue. However, modifying all relevant tests would be extensive work, so this PR limits its scope to modifications to theStorageSupplier. This should result in most tests being fixed, thereby reducing the likelihood of CI failures.From my understanding, this issue only occurs when creating
Engineobjects frequently—like in CI scenarios. It doesn't happen in normal user usage.The master branch ran the CI 10 times, with one failure (attempt 7 at https://github.com/not522/optuna/actions/runs/18522577119). Meanwhile, this PR never failed for this error (https://github.com/not522/optuna/actions/runs/18548728266; attempt 5 failed for a different reason).
Description of the changes
StorageSupplier