Skip to content

fix(oauth): close sqlite3 connections in the installation and state stores - #2098

Merged
WilliamBergamin merged 7 commits into
mainfrom
fix/sqlite3-close-connections
Dec 1, 2026
Merged

WilliamBergamin merged 7 commits into
mainfrom
fix/sqlite3-close-connections

Conversation

@WilliamBergamin

Copy link
Copy Markdown
Contributor

Summary

This pull request closes the sqlite3 connections opened by SQLite3InstallationStore and SQLite3OAuthStateStore.

  • Using a sqlite3.Connection as a context manager commits or rolls back, but it never closes the connection. So every store call left its connection for garbage collection, and on Python 3.13+ each one emits ResourceWarning: unclosed database.
  • All 12 with ... as conn: sites now use contextlib.closing, init() and create_tables() included. Every write already calls conn.commit() itself, and closing a connection discards an uncommitted transaction the same way the old rollback did.
  • tests/helpers.py gains record_return_values, which keeps each connection alive so the new tests can check that it was closed. Without it, garbage collection would close the connection and the tests would pass on main.

Testing

On Python 3.13+, run python -W always::ResourceWarning -m pytest tests/slack_sdk/oauth/state_store/test_sqlite3.py. main prints unclosed database warnings and this branch prints none. The new test_closes_every_connection tests fail on main and pass here.

Category

  • slack_sdk.web.WebClient (sync/async) (Web API client)
  • slack_sdk.webhook.WebhookClient (sync/async) (Incoming Webhook, response_url sender)
  • slack_sdk.socket_mode (Socket Mode client)
  • slack_sdk.signature (Request Signature Verifier)
  • slack_sdk.oauth (OAuth Flow Utilities)
  • slack_sdk.models (UI component builders)
  • slack_sdk.scim (SCIM API client)
  • slack_sdk.audit_logs (Audit Logs API client)
  • slack_sdk.rtm_v2 (RTM client)
  • /docs (Documents)
  • /tutorial (PythOnBoardingBot tutorial)
  • tests/integration_tests (Automated tests for this library)

Requirements

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I have signed the Salesforce CLA (required before your PR can be reviewed or merged).
  • I've run python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.sh after making the changes.

🤖 Generated with Claude Code

…tores

A sqlite3 Connection used as a context manager commits or rolls back but
never closes, so every store call left its connection to garbage
collection (a ResourceWarning on Python 3.13+). Wrap all twelve sites in
contextlib.closing; every write already commits explicitly.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@WilliamBergamin WilliamBergamin added this to the 3.48.1 milestone Dec 1, 2026
@WilliamBergamin WilliamBergamin added bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:patch oauth labels Dec 1, 2026
@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.96%. Comparing base (87516f6) to head (80b1e14).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2098   +/-   ##
=======================================
  Coverage   84.96%   84.96%           
=======================================
  Files         118      118           
  Lines       14285    14287    +2     
=======================================
+ Hits        12137    12139    +2     
  Misses       2148     2148           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@WilliamBergamin WilliamBergamin self-assigned this Dec 1, 2026
@WilliamBergamin
WilliamBergamin marked this pull request as ready for review December 1, 2026 19:15
@WilliamBergamin
WilliamBergamin requested a review from a team as a code owner December 1, 2026 19:15

@mwbrooks mwbrooks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Thanks @WilliamBergamin, no more unclosed database warnings on 3.13 and the tests prove it.

Comment thread tests/helpers.py


@contextmanager
def record_return_values(module: Any, name: str) -> Iterator[List[Any]]:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Keeping each connection alive is the clever bit here, since without it garbage collection closes them and the test would pass on main too.

@zimeg zimeg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐍 @WilliamBergamin LGTM! Every write already commits on its own, so closing these connections is a tidy fix 🧹

@WilliamBergamin
WilliamBergamin enabled auto-merge (squash) December 1, 2026 19:58
@WilliamBergamin
WilliamBergamin merged commit f69c507 into main Dec 1, 2026
33 of 34 checks passed
@WilliamBergamin
WilliamBergamin deleted the fix/sqlite3-close-connections branch December 1, 2026 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented oauth semver:patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants