diff options
author | Micah Anderson <micah@riseup.net> | 2014-04-17 15:43:11 -0400 |
---|---|---|
committer | Micah Anderson <micah@riseup.net> | 2014-04-17 15:43:11 -0400 |
commit | c8f5443e0998d3d3d43505ff5a6fdf8c438d6c24 (patch) | |
tree | 4cec9402bfe7775f5c261e26cefb2e63a05a4817 | |
parent | 32dba50beb0c24b9b883e495149b353aa70506c6 (diff) |
fix for narrow timing issue that occurs when the check for a document existence fails, but then the document appears in the cluster before the script is able to put the document, causing a 409 Conflict (#5523)
-rw-r--r-- | files/couch-doc-update | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/files/couch-doc-update b/files/couch-doc-update index 242ed14..5ceed5e 100644 --- a/files/couch-doc-update +++ b/files/couch-doc-update @@ -90,6 +90,7 @@ end # update document # def set_document(db, id, data) + attempt ||= 1 doc = get_document(db, id) if doc doc.id ||= id @@ -97,6 +98,11 @@ def set_document(db, id, data) else create_document(db, id, data) end +rescue RestClient::Conflict + # retry once, reraise if that does not work + raise if attempt > 1 + attempt += 1 + retry end def get_document(db, doc_id) |