Browse Source

Fix synchronization in ResponseBodyEmitter

See gh-35423
Fixes gh-35466

(cherry picked from commit 20e1149dde)
pull/35587/head
Brian Clozel 3 months ago committed by Juergen Hoeller
parent
commit
b213344d25
  1. 8
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java

8
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java

@ -201,10 +201,10 @@ public class ResponseBodyEmitter { @@ -201,10 +201,10 @@ public class ResponseBodyEmitter {
* @throws java.lang.IllegalStateException wraps any other errors
*/
public void send(Object object, @Nullable MediaType mediaType) throws IOException {
Assert.state(!this.complete, () -> "ResponseBodyEmitter has already completed" +
(this.failure != null ? " with error: " + this.failure : ""));
this.writeLock.lock();
try {
Assert.state(!this.complete, () -> "ResponseBodyEmitter has already completed" +
(this.failure != null ? " with error: " + this.failure : ""));
if (this.handler != null) {
try {
this.handler.send(object, mediaType);
@ -235,10 +235,10 @@ public class ResponseBodyEmitter { @@ -235,10 +235,10 @@ public class ResponseBodyEmitter {
* @since 6.0.12
*/
public void send(Set<DataWithMediaType> items) throws IOException {
Assert.state(!this.complete, () -> "ResponseBodyEmitter has already completed" +
(this.failure != null ? " with error: " + this.failure : ""));
this.writeLock.lock();
try {
Assert.state(!this.complete, () -> "ResponseBodyEmitter has already completed" +
(this.failure != null ? " with error: " + this.failure : ""));
sendInternal(items);
}
finally {

Loading…
Cancel
Save