@@ -57,7 +57,7 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse {
57
57
* response during which time pre-commit actions can still make changes to
58
58
* the response status and headers.
59
59
*/
60
- private enum State {NEW , COMMITTING , COMMITTED }
60
+ private enum State {NEW , COMMITTING , COMMIT_ACTION_FAILED , COMMITTED }
61
61
62
62
protected final Log logger = HttpLogging .forLogName (getClass ());
63
63
@@ -204,7 +204,8 @@ public void beforeCommit(Supplier<? extends Mono<Void>> action) {
204
204
205
205
@ Override
206
206
public boolean isCommitted () {
207
- return this .state .get () != State .NEW ;
207
+ State state = this .state .get ();
208
+ return (state != State .NEW && state != State .COMMIT_ACTION_FAILED );
208
209
}
209
210
210
211
@ Override
@@ -251,19 +252,22 @@ protected Mono<Void> doCommit() {
251
252
* @return a completion publisher
252
253
*/
253
254
protected Mono <Void > doCommit (@ Nullable Supplier <? extends Mono <Void >> writeAction ) {
254
- if (!this .state .compareAndSet (State .NEW , State .COMMITTING )) {
255
- return Mono .empty ();
256
- }
257
-
258
255
Flux <Void > allActions = Flux .empty ();
259
-
260
- if (!this .commitActions .isEmpty ()) {
261
- allActions = Flux .concat (Flux .fromIterable (this .commitActions ).map (Supplier ::get ))
262
- .doOnError (ex -> {
263
- if (this .state .compareAndSet (State .COMMITTING , State .NEW )) {
264
- getHeaders ().clearContentHeaders ();
265
- }
266
- });
256
+ if (this .state .compareAndSet (State .NEW , State .COMMITTING )) {
257
+ if (!this .commitActions .isEmpty ()) {
258
+ allActions = Flux .concat (Flux .fromIterable (this .commitActions ).map (Supplier ::get ))
259
+ .doOnError (ex -> {
260
+ if (this .state .compareAndSet (State .COMMITTING , State .COMMIT_ACTION_FAILED )) {
261
+ getHeaders ().clearContentHeaders ();
262
+ }
263
+ });
264
+ }
265
+ }
266
+ else if (this .state .compareAndSet (State .COMMIT_ACTION_FAILED , State .COMMITTING )) {
267
+ // Skip commit actions
268
+ }
269
+ else {
270
+ return Mono .empty ();
267
271
}
268
272
269
273
allActions = allActions .concatWith (Mono .fromRunnable (() -> {
0 commit comments