Skip to content

Conversation

acktsap
Copy link
Contributor

@acktsap acktsap commented Sep 4, 2025

Closes gh-35422

* @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();
Copy link
Contributor Author

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 4, 2025
@acktsap acktsap force-pushed the topic/sse-thread-pinning branch from 80535b1 to f9a40be Compare September 4, 2025 15:41
@bclozel
Copy link
Member

bclozel commented Sep 4, 2025

@acktsap please run the build locally before submitting a PR: ./gradlew check.
You can then git push --force to your branch to update this PR.

@acktsap acktsap force-pushed the topic/sse-thread-pinning branch from f9a40be to ebce252 Compare September 4, 2025 15:51
@acktsap
Copy link
Contributor Author

acktsap commented Sep 4, 2025

@acktsap please run the build locally before submitting a PR: ./gradlew check. You can then git push --force to your branch to update this PR.

Completed

@bclozel bclozel added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 9, 2025
@bclozel bclozel self-assigned this Sep 9, 2025
@bclozel bclozel added this to the 6.2.x milestone Sep 9, 2025
@bclozel bclozel closed this in c788554 Sep 9, 2025
@bclozel bclozel modified the milestones: 6.2.x, 6.2.11 Sep 9, 2025
Copy link
Contributor

github-actions bot commented Sep 9, 2025

Fixed via c788554

@bclozel
Copy link
Member

bclozel commented Sep 9, 2025

Thanks for raising this @acktsap , this is now merged.

@acktsap acktsap deleted the topic/sse-thread-pinning branch September 9, 2025 16:24
@@ -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" +
Copy link
Contributor

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

Copy link
Contributor

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.

bclozel added a commit that referenced this pull request Sep 12, 2025
jhoeller pushed a commit that referenced this pull request Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid pinning in SSEEmitter & ResponseBodyEmitter
4 participants