Files
ec0ca46334 fix(server): run ResourceCleaner on signal shutdown instead of racing Fatalf exit (#3804)
* fix(server): signal shutdown raced Fatalf exit before ResourceCleaner ran

The signal goroutine closed the listener before calling server.Shutdown,
so Serve returned the raw accept error ('use of closed network connection')
instead of ErrServerClosed. The invoke error path then hit logger.Fatalf
(os.Exit(1)) in the same millisecond, killing the process before the
shutdown goroutine reached resourceCleaner.Cleanup. Every registered
cleaner — BrowserSkill daemon, sandbox reapers, IMService, AntsPool,
Langfuse — was skipped on every SIGTERM/SIGINT, leaking the shared bsk
daemon process and its temp home on each restart.

Two changes:
- Drop the manual listener.Close(): Shutdown closes all listeners as its
  first step, releasing the port just as fast without racing Serve.
- Give resourceCleaner.Cleanup its own fresh timeout context so a slow
  connection drain cannot leave Cleanup with an already-expired context,
  which made it skip every entry without running any.

* fix(server): keep signal cleanup inside one grace period

Desktop quit still closed the listener before Shutdown and returned
before ResourceCleaner finished, so Fatalf could skip every hook.
Share ShutdownTimeout between drain and cleanup, run BrowserSkill
first, and do not drop later hooks when the deadline expires.

* fix(server): satisfy errcheck and line-length lint

---------

Co-authored-by: vicfei <vicfei@users.noreply.github.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-28 23:37:36 +08:00
..