Skip to content

[BUG](sysdb): Take write lock in delete_collection - #7522

Open
vishnujayvel wants to merge 1 commit into
chroma-core:mainfrom
vishnujayvel:fix/delete-collection-begin-immediate-7375
Open

[BUG](sysdb): Take write lock in delete_collection#7522
vishnujayvel wants to merge 1 commit into
chroma-core:mainfrom
vishnujayvel:fix/delete-collection-begin-immediate-7375

Conversation

@vishnujayvel

Copy link
Copy Markdown

SqliteSysDb::delete_collection opens its transaction with begin(), which starts a deferred SQLite transaction — the write lock isn't taken until the first actual write. In that window another connection can open its own transaction on the same collection name and interleave, so a concurrent create/delete pair can both report success and lose an update. create_collection already guards against this by following begin() with begin_immediate(); delete_collection did not. Credit to @roli-lpci for reporting #7375 and pinning down that asymmetry — the diagnosis in the issue is exactly right.

This adds the same begin_immediate() call so the write lock is acquired up front and the two paths behave consistently.

let mut tx = self.db.get_conn().begin().await?;
// now also in delete_collection, matching create_collection:
self.db.begin_immediate(&mut *tx).await?;

Verified with cargo test -p chroma-sysdb sqlite:: (15 passed), cargo fmt --check, and cargo clippy -p chroma-sysdb --lib -- -D warnings, on a branch merged with current main.

Closes #7375

🤖 Generated with Claude Code

delete_collection opened a deferred transaction, so SQLite did not
acquire the write lock until the first write. A concurrent create and
delete on the same collection name could therefore interleave and lose
an update. create_collection already calls begin_immediate for exactly
this reason; do the same here.

Closes chroma-core#7375

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions

Copy link
Copy Markdown

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

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.

[Bug]: Concurrent create_collection + delete_collection on the same collection name causes lost update (both return success)

1 participant