[PR #8953] [MERGED] fix(server): a pending notices lookup can't hold Restart Server or shutdown #8910

Closed
opened 2026-11-08 00:50:45 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8953
Author: @SpicyMarinara
Created: 11/7/2026
Status: ✅ Merged
Merged: 11/7/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/notices-dns-exit


📝 Commits (2)

  • c752bc1 fix(server): resolve the notices host with c-ares so a stalled lookup cannot hold exit
  • 106a35d fix(server): harden the c-ares notices lookup after review

📊 Changes

5 files changed (+429 additions, -4 deletions)

View changed files

📝 docs/CONFIGURATION.md (+3 -1)
📝 packages/server/src/routes/notices.routes.ts (+92 -1)
📝 packages/server/src/utils/security.ts (+9 -2)
➕ scripts/regressions/fixtures/stalled-resolver.mjs (+49 -0)
➕ scripts/regressions/marinara-notices-dns-exit.regression.ts (+276 -0)

📄 Description

Linked issue

Closes #8948

Why this change

On a stalled system resolver, Restart Server, signal shutdown and the force-exit fallback could hang for up to ~30 s. A launcher Ctrl+C then ended with a SIGKILL and exit 137. The notices fetch resolved raw.githubusercontent.com with getaddrinfo on the libuv threadpool, and process.exit() waits for pending threadpool work. #8947 found this through the restart-supervisor flake.

What changed

  • packages/server/src/routes/notices.routes.ts: each refresh builds its own dispatcher, through the existing createDispatcher, which already honours NODE_USE_ENV_PROXY. Its custom lookup:
    • maps localhost to 127.0.0.1 and ::1;
    • reads the hosts file (/etc/hosts, or the Windows drivers\etc\hosts), so a pinned raw.githubusercontent.com and Docker's extra_hosts still work;
    • asks c-ares (dns.resolve4/resolve6), which doesn't use the threadpool. It returns as soon as one family answers and gives the other at most 1 s more, so a router that drops AAAA queries can't stall it.
  • The same lookup goes to the proxy connector (proxyTls.lookup), so a proxy given by host name doesn't fall back to getaddrinfo.
  • redirect: "error" and the 10 s timeout are unchanged, and MARINARA_NOTICES_ENABLED=false returns before any DNS work.
  • The resolver and dispatcher are built inside the refresh's try. A malformed HTTP(S)_PROXY (for example 127.0.0.1:10809 with no scheme) now logs a warning instead of crashing the server through an unhandled rejection.
  • If c-ares can't answer, that refresh fails with the usual warning and the last notices stay. It never falls back to getaddrinfo. A ponytail: comment records the limit and the upgrade path, a child-process lookup.
  • packages/server/src/utils/security.ts: createDispatcher is exported, and it keeps a caller's proxyTls options when adding keepalive. Other callers behave as before.
  • docs/CONFIGURATION.md: the notices host, and an outbound proxy's host, are found through the hosts file and DNS servers only, so .local and short names other than localhost don't work. It also explains Termux's resolver config.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

Run by the agents (not a substitute for the boxes above):

  • New marinara-notices-dns-exit.regression.ts, with a stalled-resolver preload. Child servers call the real /api/admin/restart while the notices lookup is in flight:
    • the old fetch holds process.exit for the stall;
    • the new fetch exits in 9–25 ms with the DNS query still pending;
    • with DNS answering, the notice loads from a local server and the process exits promptly.
    • It also covers hosts-file parsing, the env proxy (named and IP), a router dropping AAAA, and a malformed proxy not rejecting.
    • Each fix fails the regression when reverted.
  • The issue's probe with a 15 s stall: the process is gone in 1.5 s (was 15.06 s). The real notices URL still loads (HTTP 200).
  • pnpm check, plus marinara-notices, admin-server-restart, restart-supervisor, restart-diagnostics, shutdown-deadline, server-signal-shutdown, robustness-shutdown-safety, route-rate-limits, llm-env-proxy and safe-fetch-redirect-local-trust: pass.

Still to verify by hand:

  • Manually verify that notices still appear on Docker, on Termux and on Windows.
  • Manually verify that Restart Server returns promptly on a network with a slow or blocked DNS.

Known limits, also documented:

  • On Termux the default resolver config uses Google DNS, so where that's blocked, notices fail with a warning.
  • A custom MARINARA_NOTICES_URL on a .local or short name no longer resolves.
  • Other outbound fetches (providers, safeFetch) still use getaddrinfo, which is out of scope here.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/8953 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 11/7/2026 **Status:** ✅ Merged **Merged:** 11/7/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/notices-dns-exit` --- ### 📝 Commits (2) - [`c752bc1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c752bc1a2ca4e8e1cdcfe95eba904b7e4d44d2a9) fix(server): resolve the notices host with c-ares so a stalled lookup cannot hold exit - [`106a35d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/106a35df14016d6975ce354fdb7b466a4bda1fa5) fix(server): harden the c-ares notices lookup after review ### 📊 Changes **5 files changed** (+429 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `docs/CONFIGURATION.md` (+3 -1) 📝 `packages/server/src/routes/notices.routes.ts` (+92 -1) 📝 `packages/server/src/utils/security.ts` (+9 -2) ➕ `scripts/regressions/fixtures/stalled-resolver.mjs` (+49 -0) ➕ `scripts/regressions/marinara-notices-dns-exit.regression.ts` (+276 -0) </details> ### 📄 Description ## Linked issue Closes #8948 ## Why this change On a stalled system resolver, **Restart Server**, signal shutdown and the force-exit fallback could hang for up to ~30 s. A launcher Ctrl+C then ended with a SIGKILL and exit 137. The notices fetch resolved `raw.githubusercontent.com` with `getaddrinfo` on the libuv threadpool, and `process.exit()` waits for pending threadpool work. #8947 found this through the restart-supervisor flake. ## What changed - `packages/server/src/routes/notices.routes.ts`: each refresh builds its own dispatcher, through the existing `createDispatcher`, which already honours `NODE_USE_ENV_PROXY`. Its custom `lookup`: - maps `localhost` to 127.0.0.1 and ::1; - reads the hosts file (`/etc/hosts`, or the Windows `drivers\etc\hosts`), so a pinned `raw.githubusercontent.com` and Docker's `extra_hosts` still work; - asks c-ares (`dns.resolve4`/`resolve6`), which doesn't use the threadpool. It returns as soon as one family answers and gives the other at most 1 s more, so a router that drops AAAA queries can't stall it. - The same lookup goes to the proxy connector (`proxyTls.lookup`), so a proxy given by host name doesn't fall back to `getaddrinfo`. - `redirect: "error"` and the 10 s timeout are unchanged, and `MARINARA_NOTICES_ENABLED=false` returns before any DNS work. - The resolver and dispatcher are built inside the refresh's `try`. A malformed `HTTP(S)_PROXY` (for example `127.0.0.1:10809` with no scheme) now logs a warning instead of crashing the server through an unhandled rejection. - If c-ares can't answer, that refresh fails with the usual warning and the last notices stay. It never falls back to `getaddrinfo`. A `ponytail:` comment records the limit and the upgrade path, a child-process lookup. - `packages/server/src/utils/security.ts`: `createDispatcher` is exported, and it keeps a caller's `proxyTls` options when adding keepalive. Other callers behave as before. - `docs/CONFIGURATION.md`: the notices host, and an outbound proxy's host, are found through the hosts file and DNS servers only, so `.local` and short names other than `localhost` don't work. It also explains Termux's resolver config. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes Run by the agents (not a substitute for the boxes above): - New `marinara-notices-dns-exit.regression.ts`, with a stalled-resolver preload. Child servers call the real `/api/admin/restart` while the notices lookup is in flight: - the old fetch holds `process.exit` for the stall; - the new fetch exits in 9–25 ms with the DNS query still pending; - with DNS answering, the notice loads from a local server and the process exits promptly. - It also covers hosts-file parsing, the env proxy (named and IP), a router dropping AAAA, and a malformed proxy not rejecting. - Each fix fails the regression when reverted. - The issue's probe with a 15 s stall: the process is gone in 1.5 s (was 15.06 s). The real notices URL still loads (HTTP 200). - `pnpm check`, plus `marinara-notices`, `admin-server-restart`, `restart-supervisor`, `restart-diagnostics`, `shutdown-deadline`, `server-signal-shutdown`, `robustness-shutdown-safety`, `route-rate-limits`, `llm-env-proxy` and `safe-fetch-redirect-local-trust`: pass. Still to verify by hand: - Manually verify that notices still appear on Docker, on Termux and on Windows. - Manually verify that Restart Server returns promptly on a network with a slow or blocked DNS. Known limits, also documented: - On Termux the default resolver config uses Google DNS, so where that's blocked, notices fail with a warning. - A custom `MARINARA_NOTICES_URL` on a `.local` or short name no longer resolves. - Other outbound fetches (providers, `safeFetch`) still use `getaddrinfo`, which is out of scope here. ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README) as needed - [x] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-08 00:50:45 +07:00
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
Pasta-Devs/Marinara-Engine#8910
No description provided.