[JAVA-4027] Mono#doOnTerminate does not guarantee execution prior to Subscriber notification Created: 01/Mar/21  Updated: 28/Oct/23  Resolved: 02/Mar/21

Status: Closed
Project: Java Driver
Component/s: Reactive Streams
Affects Version/s: 4.2.0
Fix Version/s: 4.2.2

Type: Bug Priority: Minor - P4
Reporter: Jeffrey Yemin Assignee: Jeffrey Yemin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to JAVA-3969 Investigate implicit session test fai... Closed

 Description   

The sessions specification requires that an implicit session is available for re-use after the previous operation that is using it completes. Currently, we rely on the use of Mono:doOnTerminate to help provide that guarantee, as in current versions of Project Reactor there is a documented guarantee that the termination code will execute prior to Subscriber notification.

But that guarantee is not included, and is violated, in the current minimum release of Project Reactor that we support (Californium). Therefore, until we update our minimum supported Project Reactor release, we should ensure that the driver behaves consistently and as expected when using that release. This is easy to do: instead of releasing the binding via Mono#doOnTerminate, wrap the sinkToCallback in another callback that releases the binding before notifying the Sink of completion.



 Comments   
Comment by Githook User [ 02/Mar/21 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@mongodb.com', 'username': 'jyemin'}

Message: Ensure that AsyncReadWriteBinding is released prior to subscriber notification (#676)

Previously the driver assumed that Mono#doOnTerminate is executed
prior to the subscriber being notified of completion. But it turns
out that behavior is not guaranteed in the Californium release of
Project Reactor (though it is in later releases). So instead,
now the SingleResultCallback that is used to notify the Mongo of
completion is wrapped by one that first releases the binding, and
Mono#doOnTerminate is no longer used.

JAVA-4027
Branch: 4.2.x
https://github.com/mongodb/mongo-java-driver/commit/44b1e8987c71a1caf1e444b83049b4d4a22c17a4

Comment by Githook User [ 02/Mar/21 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@mongodb.com', 'username': 'jyemin'}

Message: Ensure that AsyncReadWriteBinding is released prior to subscriber notification (#676)

Previously the driver assumed that Mono#doOnTerminate is executed
prior to the subscriber being notified of completion. But it turns
out that behavior is not guaranteed in the Californium release of
Project Reactor (though it is in later releases). So instead,
now the SingleResultCallback that is used to notify the Mongo of
completion is wrapped by one that first releases the binding, and
Mono#doOnTerminate is no longer used.

JAVA-4027
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/dfff51f4f805e6c2c798216df1878d0b0c27018c

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