ClickHouse / ClickHouse/clickhouse-odbc
Multithreading: got code SQL_INVALID_HANDLE when SQLGetData called
- Dominant language
- C
- Stars
- 285
- Forks
- 105
- Avg merge
- 3h 56m
- Merged PRs (30d)
- 3
Description
As the title suggests, I encountered the SQL_INVALID_HANDLE error from SQLGetData function. It appears that the Driver::call function is not thread safe.
To address this issue, I attempted to add a return code in order to obtain the error code -99:

In my program, multiple threads call ODBC functions simultaneously. Therefore, I suspect that when one thread is executing SQLGetData, and another thread is creating a new session, the 'descendants' variable is not protected by thread safety measures.
Contributor guide
Research direction
Start by inspecting the Driver::call function and how the descendants variable is accessed during SQLGetData and new-session creation. Reproduce concurrent ODBC calls from multiple threads, then verify that simultaneous SQLGetData and session creation no longer produce SQL_INVALID_HANDLE or error code -99.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, clickhouse, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100