Skip to content

Commit 9e1121f

Browse files
committed
Document behavior on reactive tx cancellation
Closes gh-25091
1 parent 0ccf5e1 commit 9e1121f

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionalOperator.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,9 +38,10 @@
3838
* application services utilizing this class, making calls to the low-level
3939
* services via an inner-class callback object.
4040
*
41-
* <p>Transactional Publishers should avoid Subscription cancellation.
42-
* Cancelling initiates asynchronous transaction cleanup that does not allow for
43-
* synchronization on completion.
41+
* <p><strong>Note:</strong> Transactional Publishers should avoid Subscription
42+
* cancellation. See the
43+
* <a href="https://docs.spring.io/spring/docs/current/spring-framework-reference/data-access.html#tx-prog-operator-cancel">Cancel Signals</a>
44+
* section of the Spring Framework reference for more details.
4445
*
4546
* @author Mark Paluch
4647
* @author Juergen Hoeller

src/docs/asciidoc/data-access.adoc

+20
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,11 @@ programming arrangements as the following listing shows:
14571457
}
14581458
----
14591459

1460+
Note that there are special considerations for the returned `Publisher` with regards to
1461+
Reactive Streams cancellation signals. See the <<tx-prog-operator-cancel>> section under
1462+
"Using the TransactionOperator" for more details.
1463+
1464+
14601465
.Method visibility and `@Transactional`
14611466
****
14621467
When you use proxies, you should apply the `@Transactional` annotation only to methods
@@ -2446,6 +2451,21 @@ method on the supplied `ReactiveTransaction` object, as follows:
24462451
})
24472452
----
24482453

2454+
[[tx-prog-operator-cancel]]
2455+
===== Cancel Signals
2456+
2457+
In Reactive Streams, a `Subscriber` can cancel its `Subscription` and terminate its
2458+
`Publisher`. Operators in Project Reactor, as well as in other libraries, such as `next()`,
2459+
`take(long)`, `timeout(Duration)`, and others can issue cancellations. There is no way to
2460+
know the reason for the cancellation, whether it is due to an error or a simply lack of
2461+
interest to consume further, and in version 5.2 the `TransactionalOperator` defaults to
2462+
committing the transaction on cancel. In version 5.3 this behavior will change and
2463+
transactions will be roll back on cancel to create a reliable and deterministic outcome.
2464+
As a result it is important to consider the operators used downstream from a transaction
2465+
`Publisher`. In particular in the case of a `Flux` or other multi-value `Publisher`,
2466+
the full output must be consumed to allow the transaction to complete.
2467+
2468+
24492469
[[tx-prog-operator-settings]]
24502470
===== Specifying Transaction Settings
24512471

0 commit comments

Comments
 (0)