Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging a Spring WebFlux / Reactor application with IntelliJ IDEA

I'm creating an Spring WebFlux / Reactor application with IntelliJ IDEA. The debugger of IDEA shows many useless lines like MonoDefer, MonoFlatMap, etc. Is there a way to trace the stacks easily?

intellij-debug-traces

like image 875
sunnyone Avatar asked Jun 29 '18 10:06

sunnyone


People also ask

What is Reactor debug mode in IntelliJ?

Reactor debug mode IntelliJ IDEA is aware of the Reactor debug mode and shows the traceback to the failed operation on the Frame tab of the Debug tool window. Moreover, IntelliJ IDEA can enable the debug mode without any changes in your code, making the necessary calls as you run the debugging session.

How do I enable debugging in IntelliJ?

Click the Run icon in the gutter, then select Modify Run Configuration. Enter arguments in the Program arguments field. Click the Run button near the main method. From the menu, select Debug.


1 Answers

In an asynchronous world, unfortunately stack traces lose a lot of their meaning. Here you see a stack that shows the operators making up the whole of the reactive chain (including the ones the Spring Framework uses on top of those you defined in your controller). The only problem is it shows where the chain was triggered (or "subscribed"), because the execution is lazy and that's the only path visible at runtime...

For errors and stack traces proper, there is a .checkpoint() operator that you can use explicitly in a chain in order to capture information about the "assembly" (where the chain of operators is declared in your code), to provide a bit more context. It is then shown as part of the exception stack straces, as a suppressed exception.

It was also a bit too difficult for us to use the new async debugger feature of IntelliJ because the execution model doesn't provide a fixed pair of "scheduling site vs execution site": the Scheduler abstraction used to switch threads in the middle of a sequence by operators like publishOn and subscribeOn implies arbitrary "execution sites" (an arbitrary ExecutorService, a roll-your-own-thread-pool, a Thread, ...).

I encourage you to read up on stack traces and debugging in the official reference documentation at http://projectreactor.io/docs/core/release/reference/#debugging

like image 198
Simon Baslé Avatar answered Sep 18 '22 13:09

Simon Baslé