Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a race condition that leads to a CouchDB conflict #4158

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions model/sharing/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,22 @@ func (s *sharingIndexer) setDirOrFileRevisions(oldDocDir *vfs.DirDoc, oldDocFile
}

func (s *sharingIndexer) bulkForceUpdateDoc(olddoc, doc *vfs.FileDoc) error {
// XXX We need to check that the file has not been updated between it has
// been loaded and the call to BulkUpdateDocs, as the VFS lock has been
// acquired after the file has been loaded, and CouchDB can create a
// conflict in the database if it happens (because of the new_edit: false
// option).
if olddoc != nil {
var current couchdb.JSONDoc
err := couchdb.GetDoc(s.db, consts.Files, doc.ID(), &current)
if err != nil {
return err
}
if current.Rev() != olddoc.Rev() {
return ErrInternalServerError
}
}

docs := make([]map[string]interface{}, 1)
docs[0] = map[string]interface{}{
"type": doc.Type,
Expand Down
Loading