From eed8e295295a3988caa33b4a4aee3fbdf4dc301a Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Mon, 8 Jun 2020 17:43:52 +0100 Subject: [PATCH] Document behavior on reactive tx cancellation Closes gh-25091 --- .../reactive/TransactionalOperator.java | 9 +++++---- src/docs/asciidoc/data-access.adoc | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionalOperator.java b/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionalOperator.java index f31a74290462..46afd7a3038a 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionalOperator.java +++ b/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionalOperator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,9 +38,10 @@ * application services utilizing this class, making calls to the low-level * services via an inner-class callback object. * - *

Transactional Publishers should avoid Subscription cancellation. - * Cancelling initiates asynchronous transaction cleanup that does not allow for - * synchronization on completion. + *

Note: Transactional Publishers should avoid Subscription + * cancellation. See the + * Cancel Signals + * section of the Spring Framework reference for more details. * * @author Mark Paluch * @author Juergen Hoeller diff --git a/src/docs/asciidoc/data-access.adoc b/src/docs/asciidoc/data-access.adoc index 0a319e148b1b..a8fd91252b72 100644 --- a/src/docs/asciidoc/data-access.adoc +++ b/src/docs/asciidoc/data-access.adoc @@ -1457,6 +1457,11 @@ programming arrangements as the following listing shows: } ---- +Note that there are special considerations for the returned `Publisher` with regards to +Reactive Streams cancellation signals. See the <> section under +"Using the TransactionOperator" for more details. + + .Method visibility and `@Transactional` **** 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: }) ---- +[[tx-prog-operator-cancel]] +===== Cancel Signals + +In Reactive Streams, a `Subscriber` can cancel its `Subscription` and terminate its +`Publisher`. Operators in Project Reactor, as well as in other libraries, such as `next()`, +`take(long)`, `timeout(Duration)`, and others can issue cancellations. There is no way to +know the reason for the cancellation, whether it is due to an error or a simply lack of +interest to consume further, and in version 5.2 the `TransactionalOperator` defaults to +committing the transaction on cancel. In version 5.3 this behavior will change and +transactions will be roll back on cancel to create a reliable and deterministic outcome. +As a result it is important to consider the operators used downstream from a transaction +`Publisher`. In particular in the case of a `Flux` or other multi-value `Publisher`, +the full output must be consumed to allow the transaction to complete. + + [[tx-prog-operator-settings]] ===== Specifying Transaction Settings