-
Type: Task
-
Resolution: Done
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
NODE-4492 Description
What problem are you facing?
What driver and relevant dependency versions are you using?
Steps to reproduce?
when using promise.all I sometimes get error such as:
"MongoServerError: Given transaction number 5 does not match any in-progress transactions. The active transaction number is 4"
{ ok: 0, code: 251, codeName: 'NoSuchTransaction', '$clusterTime': { clusterTime: new Timestamp( { t: 1659288270, i: 1 } )}, operationTime: new Timestamp( { t: 1659288270, i: 1 } ), [Symbol(errorLabels)]: Set(1) { 'TransientTransactionError' } }
code example:
the logic is inside main function and I use setInterval to check how many times I get the error and it seems like more than 50% of the time I get such error.
async function main(separateFirstCall) { const clientConnection = await client.connect(); const db = await client.db(dbName); const collection = await db.collection('transaction-test'); const session = clientConnection.startSession() const options = { readPreference: 'primary', readConcern: { level: 'local' }, writeConcern: { w: 'majority' }, } const names = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'] await session.withTransaction(async () => { await Promise.all(names.map(async name => { try { await collection.findOne({ name }, { session }) } catch (e) { console.log(e) } })) }, options) return 'done'} setInterval(() => { main() .then(console.log) .catch(console.error) .finally(() => client.close()); }, 5000)
- is depended on by
-
NODE-4492 NoSuchTransaction error when using promise.all
- Closed