Causes behind exception "Concurrent operations on the same resource"

Hi All,

I’m dealing with following exception when doing upsert operations in large dataset, which I couldn’t find the root cause or identify a smaller set of data that consistently reproduce the issue:

Write errors: [BulkWriteError{index=47, code=40333, message='Concurrent operations on the same resource, please try again', details={}}]. ; nested exception is com.mongodb.MongoBulkWriteException: Bulk write operation error on server

Does anyone know what the potential issues are behind this message ? Especially, what kind “resource” that the error refer to ? Or what kind of troubleshooting I can do to tackle this issue.

Thanks,
T

Hi @Tuan_Dinh,

To help investigate this, can you confirm:

  • the specific driver & version you are using
  • your MongoDB server version

I’m having trouble finding this error message in the MongoDB server source code. Are you using a hosted or emulated service?

Thanks,
Stennie

Thanks @Stennie_X for the prompt reply.

I’m using Spring Web Flux with reactive Mongo, sort of delegate to framework to deal with the driver etc.

As for the exception, it is nested within a Spring’s DataIntegrityViolationException:

exception=org.springframework.dao.DataIntegrityViolationException: Bulk write operation error on server <server>:27017. Write errors: [BulkWriteError{index=63, code=40333, message='Concurrent operations on the same resource, please try again', details={}}]. ; nested exception is com.mongodb.MongoBulkWriteException: Bulk write operation error on server <server>:27017. Write errors: [BulkWriteError{index=63, code=40333, message='Concurrent operations on the same resource, please try again', details={}}]. backoff={1000ms}

I’ve checked: The MongoBulkWriteException is with mongo-driver-core 3.11.2 which is a dependency in our service.

And yes, the server is not exactly Mongo. It’s AWS Document DB (but it is known to be mongo underneath with version 3.6 according to their doc)

So you reckon either the Spring framework or DocumentDB throws the exception ?

Thanks
T

Hi @Tuan_Dinh,

DocumentDB is actually an emulation of the MongoDB server with many functional differences and incomplete feature support versus the claimed 3.6 version compatibility (both examples are from AWS documentation).

The general messaging may be a bit unclear, but as per their documentation on functional differences:

Amazon DocumentDB emulates the MongoDB 3.6 API on a purpose-built database engine

The server error you are encountering is specific to DocumentDB, so you will have to contact AWS support or ask on a site like Stack Overflow.

Regards,
Stennie