Error 251 - Transaction XXX has been aborted

Good afternoon people

I have a Java Spring Boot application that uses Mongo (Atlas Server).
I enabled transactions with org.springframework.data.mongodb.MongoTransactionManager and everything works fine, but I have a problem.
When a given transaction exceeds 1 minute, I get the following error:

org.springframework.data.mongodb.MongoTransactionException: Query failed with error code 251 and error message ‘Transaction 643 has been aborted.’ on server XXX. nested exception is com.mongodb.MongoQueryException: Query failed with error code 251 and error message ‘Transaction 643 has been aborted.’ on server

Can someone help me?

Spring boot version: 2.3.3.RELEASE
Mongo version: 4.4.22

1 Like

Hi there, Even we faced this issue
I think we have solved it
We were using nodejs
we were using Promise.all with all our transactions,

let’s say
There are total of 10 transactions and you got error after 4 transactions, session.aborrtTransaction doesn’t work cause there are 6 more transactions in promise.all and there will be committed

You can do is
try {
// your code
}catch(e) {
await session.abortTransaction()
//This one line fixed our problem
await session.endSession
}