mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #4707] [Issue]: .env watcher stat-polls every 2s forever — highest-frequency permanent idle timer on the server #2581
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#2581
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Aug 7, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4707
Originally assigned to: @kolacheee on GitHub.
Summary
The
.envhot-reload watcher stat-polls the env file every 2 seconds for the server's lifetime (fs.watchFileis stat-polling, not inotify). It is the highest-frequency permanent timer on an idle server — individually cheap, but 30 wakeups/minute forever prevents deep idle on a phone-hosted (Termux) install.Follow-up from the mobile-battery investigation (passive-server round).
Expected behavior
Env changes are still picked up promptly (the no-restart security-config path stays intact), with near-zero idle wakeups.
Actual behavior
packages/server/src/config/env-watcher.ts:159—watchFile(envPath, { interval: 2_000, persistent: false }, handler); started unconditionally at boot (packages/server/src/index.ts:41). One stat + timer wake every 2s, forever.Steps to reproduce
.envfor the process lifetime.Environment
d6275fa0bLogs, screenshots, or video
Code trace, line references against staging
d6275fa0b.Additional context
Regression-safe fix (designed + red-teamed)
fs.watchthe parent directory of the env path, filtered to the.envbasename — directory-watching survives atomic-replace editors (rename to a new inode) and the file not existing yet, both of which break naivefs.watchon the file itself. Keep the existing mtime/size dedupe (env-watcher.ts:138-148) and add a ~250ms event debounce (inotify fires multiple events per save).fs.watcherror/unsupported filesystem (some FUSE/network mounts), fall back to the existingwatchFilehandler atinterval: 30_000instead of 2_000 — env edits are human-timescale; 30s worst-case latency cuts wakeups 15× where inotify is unavailable. (inotify works for Termux home-directory paths, where the checkout and.envlive.)MARINARA_ENV_WATCH=0opt-out, checked once at startup — but do not default it off in the Termux launcher; that would silently kill the documented no-restart security-config reload path (env-watcher.ts:4-7) for exactly the users who rely on it.Filed alongside #4704 / #4705 / #4706 from the same follow-up audit.
Template check