Skip to content

Handle intentional Granian SIGTERM shutdown - #7457

Closed
harsh21234i wants to merge 2 commits into
reflex-dev:mainfrom
harsh21234i:fix/7266-granian-sigterm-shutdown
Closed

harsh21234i wants to merge 2 commits into
reflex-dev:mainfrom
harsh21234i:fix/7266-granian-sigterm-shutdown

Conversation

@harsh21234i

@harsh21234i harsh21234i commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Closes #7266 by avoiding a misleading “Unexpected exit” error when Reflex and its Granian worker receive SIGTERM together.

The worker watcher treats SIGTERM as intentional only after Granian's supervisor has received its own interrupt signal. Worker-only SIGTERM exits retain Granian's normal failure handling and release the listener when no workers remain.

Testing

  • tests/units/utils/test_exec.py: 33 passed, 3 skipped
  • git diff --check passed

Review in cubic

@harsh21234i
harsh21234i requested a review from a team as a code owner October 6, 2026 19:18

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread tests/units/utils/test_exec.py Outdated
@greptile-apps

greptile-apps Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Changes how the development backend handles worker shutdown signals.

The PR appears safe to merge; the earlier socket-release issue is fixed.

What we checked:

  • Requests wait without a worker: A worker-only SIGTERM no longer sets interrupt_by_parent. When no worker remains alive, the watcher closes the listener.

Summary

The watcher now treats a Granian worker’s SIGTERM exit as intentional only when the supervisor is also stopping.

  • Fixes the earlier finding: stopping only the worker still releases the listening socket.
  • Adds a test for worker-only SIGTERM and closes sockets after the shutdown tests.
  • Adds a short release note. No new actionable issues were found.

Reviews (2) · Last reviewed commit: "Fix Granian worker SIGTERM socket cleanu..." · Reviewed by Greptile

Comment thread reflex/utils/exec.py Outdated
@codspeed

codspeed Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 8.74%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 149 untouched benchmarks
⏩ 18 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_hydration_metadata[200] 2 ms 1.8 ms +8.74%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing harsh21234i:fix/7266-granian-sigterm-shutdown (d96e563) with main (8239259)

Open in CodSpeed

Footnotes

  1. 18 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@masenf masenf added the on deck PRs lined up to review / merge next label Oct 9, 2026 — with ChatGPT Codex Connector

@FarhanAliRaza FarhanAliRaza left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this does not seem to fix the issue.

@FarhanAliRaza

Copy link
Copy Markdown
Contributor

Closing in favor of #7538. In a full reflex run, the worker exits 0 from its own signal handler, and the supervisor usually has not handled the signal yet, so the exitcode == -SIGTERM and interrupt_signal check never matched (the error still showed in 10 of 10 group-SIGTERM shutdowns). #7538 treats exit code 0 as a requested stop instead. Thanks for the work on this, @harsh21234i.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

on deck PRs lined up to review / merge next

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clean group-SIGTERM shutdown of dev "reflex run" still logs granian's "[ERROR] Unexpected exit from worker-1" (residual of #6981)

3 participants