question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MonoToCompletableFuture#get never return because the invocation of onComplete method before onSubscribe

See original GitHub issue

The problem comes from https://github.com/spring-projects/spring-framework/issues/26464#issue-795660549

Steps to Reproduce

A demo to reproduce:https://github.com/codergmc/websocket-demo

java.base@15.0.2/jdk.internal.misc.Unsafe.park(Native Method)
java.base@15.0.2/java.util.concurrent.locks.LockSupport.park(LockSupport.java:211)
java.base@15.0.2/java.util.concurrent.CompletableFuture$Signaller.block(CompletableFuture.java:1860) 
java.base@15.0.2/java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3137) 
java.base@15.0.2/java.util.concurrent.CompletableFuture.waitingGet(CompletableFuture.java:1887) 
java.base@15.0.2/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2062) 
app//reactor.core.publisher.MonoToCompletableFuture.get(MonoToCompletableFuture.java:81) 
app//org.springframework.util.concurrent.CompletableToListenableFutureAdapter.get(CompletableToListenableFutureAdapter.java:99) 
app//org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler$SystemSessionConnectionHandler.forward(StompBrokerRelayMessageHandler.java:1081) 
.......
  • You can find some lastest logs as follow.This mean the invocation of MonoToCompletableFuture#onComplete method before MonoToCompletableFuture#onSubscribe.Because MonoToCompletableFuture.ref is null when invoke MonoToCompletableFuture#onComplete method
2021-06-23 05:14:28.062  INFO 37138 --- [ient-loop-nio-2] r.c.publisher.MonoToCompletableFuture    : onComplete this:reactor.core.publisher.MonoToCompletableFuture@379a9335[Not completed] ref:null
2021-06-23 05:14:28.062  INFO 37138 --- [    test_thread] r.c.publisher.MonoToCompletableFuture    : onSubscribe this:reactor.core.publisher.MonoToCompletableFuture@379a9335[Not completed] ref:null
2021-06-23 05:14:28.062  INFO 37138 --- [    test_thread] r.c.publisher.MonoToCompletableFuture    : get start this:reactor.core.publisher.MonoToCompletableFuture@379a9335[Not completed, 1 dependents] ref:reactor.core.publisher.FluxContextWrite$ContextWriteSubscriber@55777635

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:18 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
violetaggcommented, Jun 28, 2021

All, let me summarise the issue:

In Spring Boot version 2.3.x, Spring Framework (based on Reactor Netty 0.9.x) uses MonoProcessor https://github.com/spring-projects/spring-framework/blob/43901b2c6a10edd0909350f6b7efefe99f4d0076/spring-core/src/main/java/org/springframework/util/concurrent/MonoToListenableFutureAdapter.java#L38

MonoProcessor guards onSubscribe/onComplete thus the issue in Reactor Netty is not visible.

In Spring Boot versions 2.4.x/2.5.x, Spring Framework (based on Reactor Netty 1.0.x), MonoToListenableFutureAdapter was rewritten and the implementation was switched to use MonoToCompletableFuture. And now the guards are not there anymore and thus the issue in Reactor Netty is revealed.

Thank you all for the reproducible example and the debugging effort!

We are going to prepare a fix for Reactor Netty.

1reaction
OlegDokukacommented, Jun 23, 2021

Indeed. This is a bug in reactor-netty. At that place, https://github.com/reactor/reactor-netty/blob/3ecd06c52263a61fb06a21fada7174f05a0d1173/reactor-netty-core/src/main/java/reactor/netty/FutureMono.java#L97 onSubscribe happens after the subscription listener is set. which means that there can be a race between onComplete and onSubscribe signaling

Read more comments on GitHub >

github_iconTop Results From Across the Web

Not calling Subscription methods in onComplete #481 - GitHub
Yes, upon a call to onComplete or onError , the Subscription should be considered cancelled and any future request or cancel calls should...
Read more >
Not able to receive onNext and onComplete call on ...
I was trying reactor library and I'm not able to figure out why below mono never return back with onNext ...
Read more >
Troubleshoot invocation issues in Lambda
When you invoke a Lambda function, Lambda validates the request and checks for scaling capacity before sending the event to your function or, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found