I build up a batch query in variable "gBatchWrite". I try to keep it around 200 operation per Amazon suggestions. Any retries after a "ConcurrentModificationException" fail. It seems that I would have to rebuild the gBatchWrite variable from scratch which is much more expensive than just retrying. Keep in mind I am running this code in separate threads that have a little overlap that causes the "ConcurrentModificationException".
I was expecting to be able to exponentially retry to execute "await gBatchWrite.iterate()" after a "ConcurrentModificationException" error. Instead all retries fail. It keeps on failing even if all other threads have finished and is the only thread left. If I run the same data in a single thread then I do not have any exceptions but is much slower.
let gBatchWrite = g
for (const jtom of batch) {
// some code here to build gBatchWrite
}
await exponentialDoTillTruthy(
async () => {
try {
await gBatchWrite.iterate()
return true
} catch (err) {
if (err.statusMessage && typeof err.statusMessage === "string") {
const errStatus = JSON.parse(err.statusMessage)
if (typeof errStatus === "object" && errStatus !== null && errStatus.code === 'ConcurrentModificationException') {
return false
}
}
throw err
}
},
50
)