Skip to content

Per-session transaction isolation: two sessions cannot hold independent transactions (storage is single-transaction) #564

Backlog

Description

@MPCoreDeveloper

Context

#563 (fixed on master, unreleased) showed that one abandoned client could disable transactions for the whole server process. The leak is fixed: every session-removal path now rolls the storage transaction back (SessionManager.RemoveSessionAsync), and SessionReaperService schedules the 30-minute expiry sweep that nothing called before.

This issue tracks the remaining "ideally" from #563: two sessions should be able to hold independent transactions at the same time. Today they cannot, and it is not a flag move.

Why it is not a flag move

  • DatabaseInstance creates one SharpCoreDB.Database; the ConnectionPool hands out PooledConnections that all point at it — a "connection" is a pool slot, not an independent engine instance.
  • The storage layer is single-transaction by construction: Services.Storage owns one TransactionBuffer + transactionLock; DirectoryStorageProvider/SingleFileStorageProvider each carry one _isInTransaction; WalManager.BeginTransaction() throws "Transaction already in progress" when one is open.
  • Table.* reads engine.IsInTransaction/storage.IsInTransaction to decide whether to wrap its own work, so a transaction is a global, non-reentrant resource per database.
  • _batchUpdateActive (Database.BatchUpdateTransaction.cs) is an extra, path-keyed layer on top; moving it to the session/connection would not enable concurrent transactions.

Options

  • B1 — server-side transaction coordinator (recommended first step): per-session logical transaction with per-session write buffering + read-your-writes, atomically applied under the global storage transaction on commit. No storage-engine change; sessions can be open concurrently.
  • B2 — true concurrent storage transactions: per-session Storage/IStorageProvider/WalManager handles merged on commit (shared file lock + conflict detection) or a multi-version WAL. Large, high-risk; touches WAL semantics, crash consistency and the reopen matrix (the hard rails in AGENTS.md / brief §11).

Full analysis: docs/server/PER_SESSION_TRANSACTION_ISOLATION.md.

Acceptance (B1)

Not in scope

Do not change the single-file/directory durability contract. Do not trade encryption or WAL semantics.

Activity

  1. added
    area:server
    on Dec 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:server

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions