Repository navigation
Conversation
|
Merging this PR will improve performance by 4.8%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | test_var_access[mutable_dataclass_list] |
483.4 ms | 461.2 ms | +4.8% |
Tip
Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.
Comparing flcrom:fix/notty-signal-shutdown (f5d8953) with main (fe2a78f)
Footnotes
-
17 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. ↩
There was a problem hiding this comment.
2 issues found across 6 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="reflex/reflex.py">
<violation number="1" location="reflex/reflex.py:453">
P2: On Windows, frontend-only SIGTERM still bypasses the new cleanup path because this condition disables both handlers. Install the handlers on Windows too, so catchable termination signals unwind `run_concurrently_context` and invoke its psutil process-tree cleanup.</violation>
</file>
<file name="tests/units/test_reflex.py">
<violation number="1" location="tests/units/test_reflex.py:640">
P2: If an assertion fails after the frontend tree has spawned, the finally block kills only `child_pid`; the grandchild stand-in for bun/node and its own child keep running in their own session for up to ~60s or longer. The child was started with `start_new_session=True`, so sending SIGKILL to its whole process group (`os.killpg(child_pid, ...)`) tears down the entire tree instead of just the leader. This is exactly the lingering-process scenario the PR targets, and a failing regression test would leak processes in CI.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| and sys.platform != "win32" | ||
| and threading.current_thread() is threading.main_thread() |
There was a problem hiding this comment.
P2: On Windows, frontend-only SIGTERM still bypasses the new cleanup path because this condition disables both handlers. Install the handlers on Windows too, so catchable termination signals unwind run_concurrently_context and invoke its psutil process-tree cleanup.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At reflex/reflex.py, line 453:
<comment>On Windows, frontend-only SIGTERM still bypasses the new cleanup path because this condition disables both handlers. Install the handlers on Windows too, so catchable termination signals unwind `run_concurrently_context` and invoke its psutil process-tree cleanup.</comment>
<file context>
@@ -436,21 +441,66 @@ def _run_dev(
+ frontend_only_signals = (
+ running_mode.has_frontend()
+ and not running_mode.has_backend()
+ and sys.platform != "win32"
+ and threading.current_thread() is threading.main_thread()
+ )
</file context>
| and sys.platform != "win32" | |
| and threading.current_thread() is threading.main_thread() | |
| and threading.current_thread() is threading.main_thread() |
| for pid in [child_pid] if child_pid else []: | ||
| if not _pid_gone(pid): | ||
| with contextlib.suppress(ProcessLookupError): | ||
| os.kill(pid, signal_mod.SIGKILL) |
There was a problem hiding this comment.
P2: If an assertion fails after the frontend tree has spawned, the finally block kills only child_pid; the grandchild stand-in for bun/node and its own child keep running in their own session for up to ~60s or longer. The child was started with start_new_session=True, so sending SIGKILL to its whole process group (os.killpg(child_pid, ...)) tears down the entire tree instead of just the leader. This is exactly the lingering-process scenario the PR targets, and a failing regression test would leak processes in CI.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tests/units/test_reflex.py, line 640:
<comment>If an assertion fails after the frontend tree has spawned, the finally block kills only `child_pid`; the grandchild stand-in for bun/node and its own child keep running in their own session for up to ~60s or longer. The child was started with `start_new_session=True`, so sending SIGKILL to its whole process group (`os.killpg(child_pid, ...)`) tears down the entire tree instead of just the leader. This is exactly the lingering-process scenario the PR targets, and a failing regression test would leak processes in CI.</comment>
<file context>
@@ -431,3 +435,268 @@ def test_init_records_version_check_after_frontend_setup(
+ for pid in [child_pid] if child_pid else []:
+ if not _pid_gone(pid):
+ with contextlib.suppress(ProcessLookupError):
+ os.kill(pid, signal_mod.SIGKILL)
+
+
</file context>
| os.kill(pid, signal_mod.SIGKILL) | |
| os.killpg(pid, signal_mod.SIGKILL) |
88b0fdf to
e4d2667
Compare
There was a problem hiding this comment.
All reported issues were addressed across 4 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Without a TTY, SIGTERM/SIGINT stopped the Granian backend but left the frontend dev server running: run_concurrently_context then blocked forever waiting on the thread streaming the child's output, and only SIGKILL of the whole process group stopped the launcher. Children spawned by run tasks are now tracked in a context-scoped registry (thread-local binding, so unrelated new_process callers are never touched) and terminated when the context unwinds - on normal exit, KeyboardInterrupt, and body failure alike. The frontend dev server runs in its own session on POSIX, so teardown signals its whole process group and grandchildren cannot survive holding the output pipe open. On Windows the tree is terminated via psutil. Late registrations during shutdown are terminated immediately. Closes reflex-dev#6980
e4d2667 to
48f8890
Compare
There was a problem hiding this comment.
All reported issues were addressed across 3 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
When
reflex runis started without a TTY (CI jobs, containers, process supervisors), SIGTERM or SIGINT stops the backend but the launcher hangs insiderun_concurrently_contextuntil something SIGKILLs the process group: the frontend dev server keeps running, its log-streaming thread never finishes, and the exit path waits on it forever.What this changes:
new_process(..., run_managed=True)are tracked on a registry scoped torun_concurrently_context. When the run unwinds, each tracked child is terminated: on POSIX the frontend is started in its own session so its whole process group (bun and its node children) gets SIGTERM, with SIGKILL escalation after a timeout; on Windows the tree is terminated via psutil. Registration is opt-in, and only the frontend dev server opts in.I reproduced the hang on current main (launcher stuck after SIGTERM until SIGKILL), then reran with this change: all four combinations (frontend-only/fullstack, SIGTERM/SIGINT) exit 0 promptly with no bun/node/granian processes left behind.
Tests:
uv run pytest -q tests/units/test_reflex.py tests/units/utils/test_processes.py tests/units/utils/test_exec.py(85 passed), ruff check/format, pyright.Closes #6980