[GH-ISSUE #1872] Ctrl+C / SIGTERM skip the clean shutdown while --open's browser launch is still running (Linux) #742

Closed
opened 2026-11-04 01:45:30 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @spratling on GitHub (Oct 10, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1872

On Linux, when --open starts the browser itself (no browser already running), webbrowser.open() waits on the launcher. Here that is /usr/bin/brave-browser, a bash wrapper that runs until the browser exits. The main thread stays inside that call for as long as the browser is open.

That call runs before both the SIGTERM handler (serve/server.py ~6308 on current main) and the try: while True: time.sleep(1) / except KeyboardInterrupt shutdown block (~6311). So while the browser is open:

  • Ctrl+C raises KeyboardInterrupt inside webbrowser.open. Python prints a traceback and exits, and the httpd.shutdown / engine.close / vision.shutdown path never runs.
  • SIGTERM gets Python's default action, because the handler is not installed yet. The process dies with no cleanup.
  • The browser is in the same process group, so Ctrl+C also takes it down.

Traceback (v0.1.40.3, Python 3.11):

^CTraceback (most recent call last):
  File ".../serve/server.py", line 5611, in <module>
    sys.exit(main())
             ^^^^^^
  File ".../serve/server.py", line 5583, in main
    webbrowser.open(f"http://{'127.0.0.1' if a.host in ('0.0.0.0', '') else a.host}:{a.port}/")
  File ".../lib/python3.11/webbrowser.py", line 87, in open
    if browser.open(url, new, autoraise):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.11/webbrowser.py", line 182, in open
    return not p.wait()
               ^^^^^^^^
  File ".../lib/python3.11/subprocess.py", line 1264, in wait
    return self._wait(timeout=timeout)
  File ".../lib/python3.11/subprocess.py", line 2046, in _wait
    (pid, sts) = self._try_wait(0)
  File ".../lib/python3.11/subprocess.py", line 2004, in _try_wait
    (pid, sts) = os.waitpid(self.pid, wait_flags)
KeyboardInterrupt

While it was stuck, the server's children were the engine, strata-vision and /bin/bash /usr/bin/brave-browser http://127.0.0.1:8081/. After the browser was closed, the main thread was back in the time.sleep(1) loop, and Ctrl+C then works normally. "open_browser": false in strata-<model>.json avoids the problem.

Possible fix: open the browser on a daemon thread (threading.Thread(target=webbrowser.open, args=(url,), daemon=True).start()), and install the SIGTERM handler before it.

Setup: Strata v0.1.40.3 started as serve/server.py --engine strata --config ... --port 8081 --open, Linux, X11, Brave as the default browser.

Originally created by @spratling on GitHub (Oct 10, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/1872 On Linux, when `--open` starts the browser itself (no browser already running), `webbrowser.open()` waits on the launcher. Here that is `/usr/bin/brave-browser`, a bash wrapper that runs until the browser exits. The main thread stays inside that call for as long as the browser is open. That call runs before both the SIGTERM handler (`serve/server.py` ~6308 on current `main`) and the `try: while True: time.sleep(1)` / `except KeyboardInterrupt` shutdown block (~6311). So while the browser is open: - Ctrl+C raises `KeyboardInterrupt` inside `webbrowser.open`. Python prints a traceback and exits, and the `httpd.shutdown` / `engine.close` / `vision.shutdown` path never runs. - SIGTERM gets Python's default action, because the handler is not installed yet. The process dies with no cleanup. - The browser is in the same process group, so Ctrl+C also takes it down. Traceback (v0.1.40.3, Python 3.11): ``` ^CTraceback (most recent call last): File ".../serve/server.py", line 5611, in <module> sys.exit(main()) ^^^^^^ File ".../serve/server.py", line 5583, in main webbrowser.open(f"http://{'127.0.0.1' if a.host in ('0.0.0.0', '') else a.host}:{a.port}/") File ".../lib/python3.11/webbrowser.py", line 87, in open if browser.open(url, new, autoraise): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../lib/python3.11/webbrowser.py", line 182, in open return not p.wait() ^^^^^^^^ File ".../lib/python3.11/subprocess.py", line 1264, in wait return self._wait(timeout=timeout) File ".../lib/python3.11/subprocess.py", line 2046, in _wait (pid, sts) = self._try_wait(0) File ".../lib/python3.11/subprocess.py", line 2004, in _try_wait (pid, sts) = os.waitpid(self.pid, wait_flags) KeyboardInterrupt ``` While it was stuck, the server's children were the engine, `strata-vision` and `/bin/bash /usr/bin/brave-browser http://127.0.0.1:8081/`. After the browser was closed, the main thread was back in the `time.sleep(1)` loop, and Ctrl+C then works normally. `"open_browser": false` in `strata-<model>.json` avoids the problem. Possible fix: open the browser on a daemon thread (`threading.Thread(target=webbrowser.open, args=(url,), daemon=True).start()`), and install the SIGTERM handler before it. Setup: Strata v0.1.40.3 started as `serve/server.py --engine strata --config ... --port 8081 --open`, Linux, X11, Brave as the default browser.
Author
Owner

@Niko1221 commented on GitHub (Oct 13, 2026):

Thanks for the report. To keep the tracker current we are closing issues older than three days: 0.1.44 is out with a long list of fixes, and many older reports are covered by it or by 0.1.43.1.

If this still happens on 0.1.44, please leave a comment here with your engine log (and the version line it prints), and we will reopen it. A new issue that links this one works too.

<!-- gh-comment-id:6156244453 --> @Niko1221 commented on GitHub (Oct 13, 2026): Thanks for the report. To keep the tracker current we are closing issues older than three days: [0.1.44](https://github.com/Niko1221/Strata/releases/tag/v0.1.44) is out with a long list of fixes, and many older reports are covered by it or by 0.1.43.1. If this still happens on 0.1.44, please leave a comment here with your engine log (and the version line it prints), and we will reopen it. A new issue that links this one works too.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#742
No description provided.