Skip to content

Commit 2ea722e

Browse files
committed
Add warning about re-entrant connections in README
1 parent 9f337c5 commit 2ea722e

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,17 @@ connector.with_client do |client|
220220
end
221221
```
222222

223+
**Warning: re-entrant connections within the same thread**
224+
225+
The `connection_pool` gem implements thread-local connection tracking. When a thread already holds a connection via `with_client` (or `check_out`), any nested call to `with_client` or `check_out` on the **same thread** returns the **same connection** — it does not check out a second one from the pool.
226+
227+
This means that if you fire an async query on a connection and then attempt to run a second query (e.g. via `run_query` or `connector.query`) from within the same `with_client` block, the nested call will receive the already-checked-out connection. Sanitization will then fail with:
228+
229+
```
230+
Connection sanitization failed: This connection is still waiting for a result,
231+
try again once you have the result
232+
```
233+
223234
It can optionally accept an existing client to avoid starting new connections in the middle of a transaction. This can be used to ensure that a series of queries are wrapped by the same transaction.
224235

225236
```ruby

0 commit comments

Comments
 (0)