Skip to content

Add graceful shutdown for SSE streams#261

Merged
rsamoilov merged 1 commit intorage-rb:mainfrom
tmchow:fix/sse-graceful-shutdown
Apr 5, 2026
Merged

Add graceful shutdown for SSE streams#261
rsamoilov merged 1 commit intorage-rb:mainfrom
tmchow:fix/sse-graceful-shutdown

Conversation

@tmchow
Copy link
Copy Markdown
Contributor

@tmchow tmchow commented Apr 4, 2026

SSE streams currently get interrupted immediately on server restart. Deferred tasks already handle this with Iodine.task_inc!/task_dec! to signal in-flight work, but SSE streams don't use the same mechanism.

This adds the same task_inc!/task_dec! calls to SSE::Application#start_stream. The server will now wait up to 15 seconds for active streams to finish before forcing shutdown, matching the existing deferred task behavior.

The ensure block guarantees task_dec! runs even if the stream raises an exception.

Closes #260

This PR was authored by a human with AI coding assistance.

Use Iodine.task_inc!/task_dec! in SSE stream fibers so the server
waits for in-progress streams to finish on restart, matching the
existing behavior of Rage::Deferred tasks.

Closes rage-rb#260
Copy link
Copy Markdown
Member

@rsamoilov rsamoilov left a comment

Choose a reason for hiding this comment

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

Looks great! Thank you, @tmchow!

@rsamoilov rsamoilov merged commit 1abb3e2 into rage-rb:main Apr 5, 2026
12 checks passed
@tmchow
Copy link
Copy Markdown
Contributor Author

tmchow commented Apr 5, 2026

Looks great! Thank you, @tmchow!

Thanks for quick merge!

anuj-pal27 pushed a commit to anuj-pal27/rage that referenced this pull request Apr 5, 2026
Use Iodine.task_inc!/task_dec! in SSE stream fibers so the server
waits for in-progress streams to finish on restart, matching the
existing behavior of Rage::Deferred tasks.

Closes rage-rb#260
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SSE] Graceful shutdown for SSE streams

2 participants