fix: resolve export_metrics crash and MTProto SIGHUP FATAL (issues #14, #15)

Issue #14: move average_latency() before export_metrics() in watchdog.uc
  - average_latency was declared AFTER export_metrics (line 1213 vs 1178)
  - in ucode timer/closure contexts the forward reference was not reliably
    resolved, causing 'left-hand side is not a function' every 2 min
  - fix: move average_latency to before export_metrics so it is always
    defined before it is referenced

Issue #15: add close_timeout to MTProxy inbound in singbox/servers.uc
  - MTProto clients maintain persistent connections that never close naturally
  - without close_timeout, sing-box waits indefinitely for them during SIGHUP
    hot-reload and exits with FATAL: 'sing-box did not close!'
  - fix: add close_timeout=10s (configurable via mtproto_close_timeout UCI)
    so sing-box forcefully closes stale MTProto connections after 10 s and
    completes the hot-reload cleanly
This commit is contained in:
Dushnilin
2026-08-07 16:20:56 +03:00
parent 59e0dc4194
commit b7fa83dfd2
2 changed files with 19 additions and 12 deletions
+4
View File
@@ -235,6 +235,10 @@ function add_standard_inbound(config, section, protocol, tag_name) {
maybe_string(inbound, "tolerate_time_skewness", option(section, "mtproto_tolerate_time_skewness", "3s"));
maybe_string(inbound, "idle_timeout", option(section, "mtproto_idle_timeout", "5m"));
maybe_string(inbound, "handshake_timeout", option(section, "mtproto_handshake_timeout", "10s"));
// Prevent SIGHUP hot-reload crash: MTProto clients keep connections alive indefinitely;
// without a close_timeout sing-box hangs waiting for them to close and exits with FATAL.
// 10 s is enough to terminate stale connections while keeping reload fast (issue #15).
maybe_string(inbound, "close_timeout", option(section, "mtproto_close_timeout", "10s"));
}
else {
inbound.users = users(section, protocol);