fix: don't close shared session store in runtime.Close#2879
Open
dgageot wants to merge 2 commits into
Open
Conversation
Reading b.store outside of storeOnce.Do has no happens-before guarantee
with the write inside Do. Use storeOnce.Do(func() {}) to fence the read.
Signed-off-by: David Gageot <david.gageot@docker.com>
004d013 to
5e988e0
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.
The TUI was failing to open
/sessionsafter switching to a session with a different working directory, with the error "failed to load sessions: sql: database is closed". This happened because when the TUI swapped in a new runtime for the different working directory, it canceled the old runtime's context and ran cleanup, which calledrt.Close()→r.sessionStore.Close(). However, the spawned new runtime was given the same SQLite store (viacreateSessionSpawnerreusingrt.SessionStore()), so closing it from the old runtime broke every subsequent read against that store.The fix moves session store ownership to the backend layer, which now owns its lifecycle independently. The
Runtime.Close()contract is updated to make explicit that the session store is owned by the embedder and may be shared.localBackendnow lazily opens the SQLite store on firstCreateSessioncall (viasync.Once) and closes it once in a newbackend.Close()method. The runtime no longer closes the store it was given, and the TUI defersb.Close()to clean up resources when the entire session ends.Fixes #2872