fix(plugin-search): transaction state errors in parallel reindex operations (#13915)
### What?
Fixed flaky MongoDB transaction state errors ("Attempted illegal state
transition from `[TRANSACTION_ABORTED]` to `[TRANSACTION_COMMITTED]`")
in plugin-search int tests.
### Why?
When reindexing multiple collections in parallel, individual collection
failures were calling `killTransaction()` on a shared
transaction that other parallel operations were still using, causing
MongoDB transaction state conflicts and test flakiness.
### How?
- Moved transaction cleanup to outer catch block only
- Removed individual `killTransaction` calls that created race
conditions
- Allow parallel operations to handle their own errors without aborting
the shared transaction
This commit is contained in:
@@ -147,7 +147,7 @@ export const generateReindexHandler =
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await initTransaction(req)
|
const shouldCommit = await initTransaction(req)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const promises = collections.map(async (collection) => {
|
const promises = collections.map(async (collection) => {
|
||||||
@@ -157,14 +157,14 @@ export const generateReindexHandler =
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
const message = t('error:unableToReindexCollection', { collection })
|
const message = t('error:unableToReindexCollection', { collection })
|
||||||
payload.logger.error({ err, msg: message })
|
payload.logger.error({ err, msg: message })
|
||||||
|
|
||||||
await killTransaction(req)
|
|
||||||
throw new Error(message)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
await Promise.all(promises)
|
await Promise.all(promises)
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
|
if (shouldCommit) {
|
||||||
|
await killTransaction(req)
|
||||||
|
}
|
||||||
return Response.json({ message: err.message }, { headers, status: 500 })
|
return Response.json({ message: err.message }, { headers, status: 500 })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,7 +174,9 @@ export const generateReindexHandler =
|
|||||||
total: aggregateDocs,
|
total: aggregateDocs,
|
||||||
})
|
})
|
||||||
|
|
||||||
await commitTransaction(req)
|
if (shouldCommit) {
|
||||||
|
await commitTransaction(req)
|
||||||
|
}
|
||||||
|
|
||||||
return Response.json({ message }, { headers, status: 200 })
|
return Response.json({ message }, { headers, status: 200 })
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user