Let only the thread that starts a DB session use it - #96
Merged
Merged
Conversation
arybczak
force-pushed
the
bound-thread
branch
from
September 16, 2026 14:53
df3ada9 to
b8099c8
Compare
arybczak
force-pushed
the
bound-thread
branch
2 times, most recently
from
September 21, 2026 18:16
70a6fc4 to
079c7e5
Compare
arybczak
force-pushed
the
bound-thread
branch
from
September 22, 2026 19:45
079c7e5 to
a4f3d51
Compare
Before, any thread could use a DB session that it got from another thread, e.g. by forking. The threads then shared one connection and one transaction. A query in one thread waited for the queries in the other threads, and a query from a forked thread ran in the transaction of the parent. If the parent session ended first, the forked thread failed. Now the thread that starts a session owns it. If another thread uses the session, the library throws ThreadMismatchError. To run queries from another thread, start a new session in that thread with withNewSession, the new name of withNewConnection. The name changed because the new session does not always acquire a connection immediately. A thread can start its new session at any time. It does not wait for the queries of the parent session, and it works also after the parent session ended.
arybczak
force-pushed
the
bound-thread
branch
from
September 22, 2026 20:02
a4f3d51 to
4753c5c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before, any thread could use a DB session that it got from another thread, e.g. by forking. The threads then shared one connection and one transaction. A query in one thread waited for the queries in the other threads, and a query from a forked thread ran in the transaction of the parent. If the parent session ended first, the forked thread failed.
Now the thread that starts a session owns it. If another thread uses the session, the library throws ThreadMismatchError. To run queries from another thread, start a new session in that thread with withNewSession, the new name of withNewConnection. The name changed because the new session does not always acquire a connection immediately.
A thread can start its new session at any time. It does not wait for the queries of the parent session, and it works also after the parent session ended.