forked from cardosofelipe/fast-next-template
fix(mcp-kb): Race condition in update_document and non-transactional batch insert #77
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Bug Description
Two concurrency issues found in the database layer:
Issue 1: Race Condition in update_document
In
database.py:update_document, there's a read-then-write pattern without proper locking:This can lead to lost updates in concurrent scenarios.
Issue 2: Non-Transactional Batch Insert
In
database.py:batch_add_documents, multiple documents are inserted without a transaction wrapper:If one insert fails, previous inserts remain, leaving data in inconsistent state.
Fix Required
SELECT ... FOR UPDATEor optimistic locking with version fieldRelated