Skip to content

Commit 20e1149

Browse files
committed
Fix synchronization in ResponseBodyEmitter
See gh-35423 Fixes gh-35466
1 parent 7a5d3a5 commit 20e1149

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ public void send(Object object) throws IOException {
198198
* @throws java.lang.IllegalStateException wraps any other errors
199199
*/
200200
public void send(Object object, @Nullable MediaType mediaType) throws IOException {
201-
Assert.state(!this.complete, () -> "ResponseBodyEmitter has already completed" +
202-
(this.failure != null ? " with error: " + this.failure : ""));
203201
this.writeLock.lock();
204202
try {
203+
Assert.state(!this.complete, () -> "ResponseBodyEmitter has already completed" +
204+
(this.failure != null ? " with error: " + this.failure : ""));
205205
if (this.handler != null) {
206206
try {
207207
this.handler.send(object, mediaType);
@@ -232,10 +232,10 @@ public void send(Object object, @Nullable MediaType mediaType) throws IOExceptio
232232
* @since 6.0.12
233233
*/
234234
public void send(Set<DataWithMediaType> items) throws IOException {
235-
Assert.state(!this.complete, () -> "ResponseBodyEmitter has already completed" +
236-
(this.failure != null ? " with error: " + this.failure : ""));
237235
this.writeLock.lock();
238236
try {
237+
Assert.state(!this.complete, () -> "ResponseBodyEmitter has already completed" +
238+
(this.failure != null ? " with error: " + this.failure : ""));
239239
sendInternal(items);
240240
}
241241
finally {

0 commit comments

Comments
 (0)