Skip to content

executeUpdate reads updateCount outside stateLock #197

Closed

Description

@magnusp

Goal

executeUpdate returns updateCount without holding stateLock. Every write happens under the lock, but the read after execute has no happens-before edge, so a concurrent close() or execute can hand back a stale count.

Where

LibsqlStatement 146 to 149 and LibsqlPreparedStatement 97 to 104 read the field directly. getUpdateCount at 449 correctly locks.

Scope

  • Add snapshotUpdateCount() that reads under stateLock.
  • Use it in both executeUpdate methods.
  • Do not add checkClosed(). Post-close executeUpdate keeps working, and the prepared statement already threw during execute.

Acceptance

  • Both update paths read the count under the lock.
  • ./mvnw -pl libsql-jdbc -am test green, including LibsqlStatementConcurrencyTest.
  • A note in the PR records that this is a correctness fix, not a refactor, and that the race is hard to reproduce without instrumentation.

Activity

  1. added
    bugSomething isn't working
    P2Normal priority: edge case, feature gap, or test/process improvement
    on Oct 24, 2026
  2. added a commit that references this issue on Oct 24, 2026
    2e05b72
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

    P2Normal priority: edge case, feature gap, or test/process improvementbugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions