Skip to content

Add a heartbeat executor for SSE emitters #34878

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

reda-alaoui
Copy link

@reda-alaoui reda-alaoui commented May 11, 2025

Fix #33355

Signed-off-by: Réda Housni Alaoui <[email protected]>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 11, 2025
@bclozel bclozel added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Jun 3, 2025
Copy link
Contributor

@rstoyanchev rstoyanchev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting together a pull request. Some comments below.

I don't think there needs to be a public SseEmitterHeartbeatExecutor contract and implementation. This could be simply a TaskScheduler with the rest managed internally in a dedicated package private class (similar to ReactiveTypeHandler).

Heartbeats should not be emitted if emitters are already busy sending. Perhaps each emitter can keep a timestamp of the last send, and expose a method to send a heartbeat that would send only if a certain amount of time has passed since the last send.

Controllers that use Flux for SSE can easily incorporate heartbeats. Such Flux return values are also turned into SseEmitters, and so adding heartbeats to every emitter you could end up with duplicate heartbeat streams for the same emitter. It makes me thing that emitters should actually opt into heartbeats, and then they should be called to send a heartbeat only if they opted in.

@rstoyanchev rstoyanchev added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 5, 2025
@rstoyanchev rstoyanchev added this to the General Backlog milestone Jun 5, 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.

Add a heartbeat executor for SSE
4 participants