Skip to content

fix: don't close shared session store in runtime.Close#2879

Open
dgageot wants to merge 2 commits into
docker:mainfrom
dgageot:board/2c638431e2df4d72
Open

fix: don't close shared session store in runtime.Close#2879
dgageot wants to merge 2 commits into
docker:mainfrom
dgageot:board/2c638431e2df4d72

Conversation

@dgageot
Copy link
Copy Markdown
Member

@dgageot dgageot commented May 22, 2026

The TUI was failing to open /sessions after 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 called rt.Close()r.sessionStore.Close(). However, the spawned new runtime was given the same SQLite store (via createSessionSpawner reusing rt.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. localBackend now lazily opens the SQLite store on first CreateSession call (via sync.Once) and closes it once in a new backend.Close() method. The runtime no longer closes the store it was given, and the TUI defers b.Close() to clean up resources when the entire session ends.

Fixes #2872

@dgageot dgageot requested a review from a team as a code owner May 22, 2026 15:34
docker-agent

This comment was marked as outdated.

docker-agent

This comment was marked as outdated.

@aheritier aheritier added area/sessions For features/issues/fixes related to session lifecycle (resume, persistence, export) kind/fix PR fixes a bug (maps to fix: commit prefix) labels May 22, 2026
aheritier

This comment was marked as outdated.

dgageot added 2 commits May 24, 2026 10:30
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sessions For features/issues/fixes related to session lifecycle (resume, persistence, export) kind/fix PR fixes a bug (maps to fix: commit prefix)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

failed to load sessions: sql: database is closed

3 participants