Skip to content

Commit 4bfb0af

Browse files
committed
fix: Ensures retryable writes on upserts in replaceUpcoming
replaceUpcoming requires a strict set of equality checks for the upsert to be retryable. A null-dleted null-acked value satisies this requirement. Values with an ack value are in the processing step. In doing this, a job in-retry will yield to the newly inserted job. Fixes #6
1 parent 8e43238 commit 4bfb0af

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/driver/mongo.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -707,12 +707,12 @@ export class MongoDriver extends BaseDriver<Db, Collection<QueueDoc>, MDBTxn> {
707707
{
708708
// uses ref, deleted, ack as key for upsert
709709
// https://www.mongodb.com/docs/manual/core/retryable-writes/#duplicate-key-errors-on-upsert
710+
// "To avoid multiple upserts, ensure that the query fields are uniquely indexed."
711+
// Do not use anything other than strict equality checks, or the upsert will not retry
712+
// and you will risk a race condition that creates duplicate keys
710713
ref: doc.ref,
711714
deleted: null,
712715
ack: null,
713-
visible: {
714-
$gte: new Date(),
715-
},
716716
},
717717
doc,
718718
{ upsert: true, session: tx?.session }

0 commit comments

Comments
 (0)