From 53774dfd76199a82e66d860f9f21c7b8e94a0ede Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Wed, 27 May 2020 19:10:24 +0100 Subject: [PATCH] Fix race condition in WriteResultPublisher between subscription and error from the Publish Closes gh-25096 --- .../http/server/reactive/WriteResultPublisher.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/WriteResultPublisher.java b/spring-web/src/main/java/org/springframework/http/server/reactive/WriteResultPublisher.java index 523050a37a8f..39f6051b4f61 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/WriteResultPublisher.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/WriteResultPublisher.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 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. @@ -182,6 +182,9 @@ void publishComplete(WriteResultPublisher publisher) { @Override void publishError(WriteResultPublisher publisher, Throwable ex) { publisher.errorBeforeSubscribed = ex; + if(State.SUBSCRIBED.equals(publisher.state.get())) { + publisher.state.get().publishError(publisher, ex); + } } }, @@ -200,6 +203,9 @@ void publishComplete(WriteResultPublisher publisher) { @Override void publishError(WriteResultPublisher publisher, Throwable ex) { publisher.errorBeforeSubscribed = ex; + if(State.SUBSCRIBED.equals(publisher.state.get())) { + publisher.state.get().publishError(publisher, ex); + } } },