Fix synchronization in ResponseBodyEmitter

See gh-35423
Fixes gh-35466
This commit is contained in:
Brian Clozel 2025-09-12 09:12:33 +02:00
parent 7a5d3a55fe
commit 20e1149dde
1 changed files with 4 additions and 4 deletions

View File

@ -198,10 +198,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);
@ -232,10 +232,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 {