[JAVA-5043] Database not being dropped using reactor-bom 2022 Created: 27/Jun/23  Updated: 27/Oct/23  Resolved: 28/Jun/23

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Unknown
Reporter: Christoph Ahlers Assignee: Ross Lawley
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

Summary

The database cannot be dropped via mongodb-driver-core 4.9.1 and reactor-bom 2022.0.8 (and before) while it works with reactor-bom 2020.0.x. The subscription's methods are not called and the database is not dropped.

It works fine with any version of reactor-bom 2020 like the current one 2020.0.33.

Tested via Spring Boot 3.1.1, Testcontainers 1.18.3, Java 20.0.1, MongoDB container "mongo:6.0" (= should be standalone).

 

How to Reproduce

Example project: github demo project

You can switch the reactor-bom version via enabling a property overriding the version defined by Spring.

2022.0.x will run into a timeout via Awaitility.
2020.0.x will succeed in dropping the database. The test will succeed.

 

Additional Background

-



 Comments   
Comment by Christoph Ahlers [ 27/Jun/23 ]

That clears that up! Thank you!

The issue can be closed!

Comment by Ross Lawley [ 27/Jun/23 ]

Hi c.ahlers@gmx.net,

Thanks for the ticket. This does highlight a difference in behaviour with project reactor versions.

All publishers from the mongodb-driver-reactivestreams are implemented as cold Publishers. They shouldn't emit any values until demand has been signalled by their Subscription. However, internally the MongoDB Reactive Streams driver utilizes Project Reactor and relies on it to provide correctness with regards to the Reactive Stream specification.

 

Project Reactor version 3.5.0 which relates to 2022.0.0 has various improvements and one relating to the change in behaviour observed here is:

The Mono stack is now more lazy and complies to the Reactive Streams specification by only evaluating the source Publisher after receiving appropriate demand. Previously this usually happened during subscription time.

This change better matches the Reactive Stream specification.  Updating your code to use the following subscriber and signal demand will work as expected:

final var subscriber = new Subscriber<Void>() {
     public boolean cleared = false;
 
     @Override
     public void onSubscribe(Subscription s) {
          System.out.println("onSubscribe");
          s.request(1);  // <<< Signal demand 
     }
 
     @Override
     public void onNext(Void unused) {
          System.out.println("onNext");
     }
 
     @Override
     public void onError(Throwable t) {
          System.out.println("ERROR during drop DB. " + t.getMessage());
     }
 
     @Override
     public void onComplete() {
          System.out.println("onComplete");
          cleared = true;
     }
};

I hope that helps.

Ross

Comment by Christoph Ahlers [ 27/Jun/23 ]

mongodb-driver-core 4.9.1 imports reactor-bom 2022.0.0, but it looks like it is not fully compatible with it

Comment by PM Bot [ 27/Jun/23 ]

Hi c.ahlers@gmx.net, thank you for reporting this issue! The team will look into it and get back to you soon.

Generated at Thu Feb 08 09:03:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.