-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Avoid thread pinning in SseEmitter, ResponseBodyEmitter #35423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
* @since 4.2 | ||
*/ | ||
public class SseEmitter extends ResponseBodyEmitter { | ||
|
||
private static final MediaType TEXT_PLAIN = new MediaType("text", "plain", StandardCharsets.UTF_8); | ||
|
||
/** Guards access to write operations on the response. */ | ||
private final Lock writeLock = new ReentrantLock(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just moved this field to the upper level & changed it to protected
80535b1
to
f9a40be
Compare
@acktsap please run the build locally before submitting a PR: |
Closes spring-projectsgh-35422 Signed-off-by: Taeik Lim <[email protected]>
f9a40be
to
ebce252
Compare
Completed |
Fixed via c788554 |
Thanks for raising this @acktsap , this is now merged. |
@@ -180,22 +197,28 @@ public void send(Object object) throws IOException { | |||
* @throws IOException raised when an I/O error occurs | |||
* @throws java.lang.IllegalStateException wraps any other errors | |||
*/ | |||
public synchronized void send(Object object, @Nullable MediaType mediaType) throws IOException { | |||
public void send(Object object, @Nullable MediaType mediaType) throws IOException { | |||
Assert.state(!this.complete, () -> "ResponseBodyEmitter has already completed" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is reading plain fields now with no synchronization
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify, I think it has introduced a bug, since the complete
and failure
fields aren't read while holding the lock.
Closes gh-35422