mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-17 01:43:52 +00:00
Merge pull request #3118 from overleaf/jpa-delay-mongo-connection-use
[scripts] batchedUpdate: try to work around flaky mongo connection setup GitOrigin-RevId: 2bba7117b8f8892a41703569fef3f97d5e8d6835
This commit is contained in:
parent
25b9243b3f
commit
00e59a9afe
1 changed files with 7 additions and 0 deletions
|
@ -1,3 +1,4 @@
|
|||
const { promisify } = require('util')
|
||||
const { ReadPreference } = require('mongodb')
|
||||
const { getNativeDb } = require('../../app/src/infrastructure/Mongoose')
|
||||
|
||||
|
@ -21,6 +22,12 @@ async function performUpdate(collection, nextBatch, update) {
|
|||
}
|
||||
|
||||
async function batchedUpdate(collectionName, query, update) {
|
||||
// Apparently the mongo driver returns the connection too early.
|
||||
// Some secondary connections are not ready as it returns, leading to
|
||||
// failing cursor actions with a readPreference set to 'secondary'.
|
||||
// TODO(das7pad): revisit/remove this delay after the mongo-driver update.
|
||||
await Promise.all([getNativeDb(), promisify(setTimeout)(10 * 1000)])
|
||||
|
||||
const db = await getNativeDb()
|
||||
const collection = db.collection(collectionName)
|
||||
|
||||
|
|
Loading…
Reference in a new issue