-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NoSuchTransaction
in reactive mongodb client when working with transactions
#4804
Comments
What I forgot to mention: |
I either see that the transaction has already been aborted which imo means that requests are sharing a transaction: org.springframework.data.mongodb.MongoTransactionException: Command failed with error 251 (NoSuchTransaction): 'Transaction with { txnNumber: 67 } has been aborted.' on server localhost:27017. The full response is {"errorLabels": ["TransientTransactionError"], "ok": 0.0, "errmsg": "Transaction with { txnNumber: 67 } has been aborted.", "code": 251, "codeName": "NoSuchTransaction", "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1728556211, "i": 10}}, "signature": {"hash": {"$binary": {"base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "subType": "00"}}, "keyId": 0}}, "operationTime": {"$timestamp": {"t": 1728556211, "i": 10}}} Or I see Error disappears when I set max connection pool size in the mongo config to |
Thank you @fremarti for getting in touch. That's a hard problem to spot - we'll look into it - thanks already for the pool size hint. |
@fremarti can you please package things up and share a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem. Thank you! |
@christophstrobl we have created a minimal-sample for you. The tests in the IntergrationTest class are flapping due to the before mentioned issue.
If you got further questions, please don't hesitate to ask. |
Setup
Spring Boot
3.3.4
withorg.springframework.boot:spring-boot-starter-webflux
andorg.springframework.boot:spring-boot-starter-data-mongodb-reactive
. MongoDB version is6.0.18
.MongoDB Config
Reactive mongo client is configured in configuration to activate transactional feature in mongo templates:
Docker Setup
For local and integration testing a mongodb is configured using docker compose. The db is configured as single node replica set. The here mentioned init script just runs
rs.initiate(...)
to register replica set. In the application properties the according connection string is set withmongodb://localhost:27017/?replicaSet=rs0
.Application Code
I have an endpoint
PUT /foo
which should update multiple entries in a single collection. This update should be transactional. Before updating the entries, all entries are fetched by ids and some validation is done before updating the entries:Integration Tests
To test the transactional behavior I wrote a Spring Boot integration test. I leveraged coroutines to fire 100 requests concurrently against the endpoint using the web test client to make sure there are no side-effects.
Unfortunately, I see side effects in the transactional behavior. On a random basis there is a
MongoTransactionException
thrown withNoSuchTransaction
instead of the expectedDataIntegrityViolationException
. Therefore this test fails and I cannot explain why that is. Can anybody help?The text was updated successfully, but these errors were encountered: