Context
PR #568 fixed a potential buffer race in Connection::setAttribute() where ptr pointed into a member field (wstrStringBuffer / strBytesBuffer) while the GIL was released. Another thread calling set_attr on the same connection could reallocate the buffer, leaving a dangling pointer for the ODBC driver.
The fix (commit 05c6ca2c) copies to stack-local buffers before the GIL release, making the race structurally impossible.
Requested Test
Add a cross-platform concurrent stress test that:
- Shares a single connection across N threads
- Each thread calls
conn.set_attr(SQL_ATTR_CURRENT_CATALOG, ...) (or another string attribute) in a tight loop with alternating short and long values to force buffer reallocation
- Asserts no crashes, no ODBC errors with garbled attribute values
This serves as a regression guard — on the fixed code it should always pass, but it would catch any future refactoring that accidentally reverts to pointing into member fields.
Notes
Related
Context
PR #568 fixed a potential buffer race in
Connection::setAttribute()whereptrpointed into a member field (wstrStringBuffer/strBytesBuffer) while the GIL was released. Another thread callingset_attron the same connection could reallocate the buffer, leaving a dangling pointer for the ODBC driver.The fix (commit
05c6ca2c) copies to stack-local buffers before the GIL release, making the race structurally impossible.Requested Test
Add a cross-platform concurrent stress test that:
conn.set_attr(SQL_ATTR_CURRENT_CATALOG, ...)(or another string attribute) in a tight loop with alternating short and long values to force buffer reallocationThis serves as a regression guard — on the fixed code it should always pass, but it would catch any future refactoring that accidentally reverts to pointing into member fields.
Notes
wchar_t == SQLWCHAR, so no conversion copy was needed). macOS/Linux were accidentally safe due to theWStringToSQLWCHARconversion creating a stack-local vector.Related
connect()(issue Reopen Issue #491: SSH tunneling fails using paramiko+sshtunnel #565)