Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix connection_wrapper destructor sometimes closing other connections #312

Merged
merged 3 commits into from
Mar 25, 2025

Conversation

meastham
Copy link
Contributor

Currently, if a dbapi connection is closed using connection.close(), and then another dbapi connection is opened before the first connection is destroyed, the destruction of the first connection's python object will cause the second connection to be closed.

This happens because connection_wrapper.conn continues to point at the global chdb_conn* after close() runs, so it's possible for the connection_wrapper destructor to close a connection it didn't create.

I used this short script to test this:

conn1 = dbapi.connect("/tmp/chdb1")
cur1 = conn1.cursor()
cur1.execute('select version()')
cur1.close()
conn1.close()

conn2 = dbapi.connect("/tmp/chdb2")
cur2 = conn2.cursor()

# Works
cur2.execute('select version()')
print(cur2.fetchone())

# Cause the closed connection to be destroyed
del cur1
del conn1

# Exception: Invalid or closed connection
cur2.execute('select version()')
print(cur2.fetchone())

the second to last line throws # Exception: Invalid or closed connection with chdb 3.1.1, but not with a wheel built from this commit.

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Fix connection_wrapper destructor sometimes closing other connections

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Information about CI checks: https://clickhouse.com/docs/en/development/continuous-integration/

CI Settings

NOTE: If your merge the PR with modified CI you MUST KNOW what you are doing
NOTE: Checked options will be applied if set before CI RunConfig/PrepareRunConfig step

Run these jobs only (required builds will be added automatically):

  • Integration Tests
  • Stateless tests
  • Stateful tests
  • Unit tests
  • Performance tests
  • All with aarch64
  • All with ASAN
  • All with TSAN
  • All with Analyzer
  • All with Azure
  • Add your option here

Deny these jobs:

  • Fast test
  • Integration Tests
  • Stateless tests
  • Stateful tests
  • Performance tests
  • All with ASAN
  • All with TSAN
  • All with MSAN
  • All with UBSAN
  • All with Coverage
  • All with Aarch64

Extra options:

  • do not test (only style check)
  • disable merge-commit (no merge from master before tests)
  • disable CI cache (job reuse)

Only specified batches in multi-batch jobs:

  • 1
  • 2
  • 3
  • 4

@CLAassistant
Copy link

CLAassistant commented Mar 21, 2025

CLA assistant check
All committers have signed the CLA.

@meastham meastham force-pushed the meastham/fix_close_race branch from e863236 to a39625c Compare March 24, 2025 20:08
@meastham
Copy link
Contributor Author

Had to force-push to fix the author on my commit so the CLA check would pass, but the content is all the same

@auxten auxten merged commit 0b97de3 into chdb-io:main Mar 25, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants