Skip to content

Conversation

@tiensi
Copy link
Contributor

@tiensi tiensi commented Nov 18, 2025

Summary

There seems to be a WAL race condition within the builder.rs file where a session is created and get session immediately after, which in some instances can fail because the read session is looking at an old version of the sessions db + WAL page from one thread before the write session commit finishes propagating.

I believe the culprit to be the lack of an explicit "commit" transaction with WAL enabled. In the concurrency section of sqlite documentation, When a read operation begins on a WAL-mode database, it first remembers the location of the last valid commit record in the WAL. So even though we were relying on concurrency through await?; the commit never applied.

This could also explain why the Pragma wal_checkpoint approach didn't work as the checkpoint didn't have a completed commit to apply WAL file changes to the database.

Type of Change

  • Feature
  • Bug fix
  • Refactor / Code quality
  • Performance improvement
  • Documentation
  • Tests
  • Security fix
  • Build / Release
  • Other (specify below)

AI Assistance

  • This PR was created or reviewed with AI assistance

Testing

I was unable to reproduce on multiple linux docker images, I went ahead and reproduced the "bug" (create_session and get_session race condition) by writing concurrent create_session -> get_session race condition tests and ran them a few thousand times.

Related Issues

Relates to #5197
Discussion:

Signed-off-by: Vincent Huang <[email protected]>
@tiensi tiensi changed the title [DO NOT REVIEW] Added wal with shared cache [VERIFICATION REQUESTED] Added wal with shared cache Nov 18, 2025
@tiensi tiensi changed the title [VERIFICATION REQUESTED] Added wal with shared cache [DO NOT REVIEW] Added wal with shared cache Nov 18, 2025
@tiensi
Copy link
Contributor Author

tiensi commented Nov 18, 2025

different approach here

@tiensi tiensi closed this Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant