OOM due to NoTransactionInContextException in reactive pipeline #34048
Labels
in: data
Issues in data modules (jdbc, orm, oxm, tx)
type: regression
A bug that is also a regression
Milestone
At commit 8e3846991d30a9a577dae9664996c036895f04cc in the Spring Framework, the
NoTransactionInContextException
was made a static instance. While this change can reduce overhead in non-reactive contexts, it introduces a potential issue in reactive pipelines: it can causeOutOfMemoryError
(OOM) due to suppressed exceptions being accumulated.In the Reactor Core implementation, as seen in the file FluxOnAssembly.java, the problem is appears at line 612:
Here, the
NoTransactionInContextException
is reused statically, and when it is thrown inside a reactive pipeline, it retains references toOnAssemblyException
instance. This can lead to suppressed exceptions being stored indefinitely, creating a memory leak.The behavior can be reproduced with the following Kotlin code:
Explanation of the Issue:
Each time the static
NO_TRANSACTION_IN_CONTEXT_EXCEPTION
is thrown within a reactive flow, theOnAssemblyException
created by Reactor is added to the suppressed exceptions of NO_TRANSACTION_IN_CONTEXT_EXCEPTION.Since the exception is static, it retains all these references, causing memory consumption to grow unbounded.
This pattern can quickly lead to an OutOfMemo`ryError, especially in high-throughput reactive applications.
The text was updated successfully, but these errors were encountered: