This site runs on my own desktop PC. Windows Task Scheduler starts Node.js at boot and a Cloudflare Tunnel brings the traffic in. A separate watchdog script checks the site every 5 minutes and restarts it if it is down.
One day I was reading the watchdog log and noticed it had been rescuing the site suspiciously often.
Start with the timestamps
Here is every time the watchdog logged a failed health check:
2026-09-04 17:16
2026-09-07 17:21
2026-09-18 03:16
2026-09-21 03:21
2026-10-07 21:31
2026-10-10 21:36
2026-10-13 21:41
2026-10-18 11:01
2026-10-21 11:06
2026-10-24 11:11
Two things stand out:
- The gaps are all 3 days
- Each failure is 5 minutes later than the previous one
The second point is the real clue. Five minutes is exactly the watchdog's interval: the site dies at some moment, and up to 5 minutes later the watchdog notices and restarts it. If "dying" is a 72-hour countdown that starts at launch, every cycle slips by 5 minutes, and the table matches perfectly. The occasional break and realignment is because I deployed on those days. A deploy restarts the site, and the countdown starts over.
There was one more coincidence. In the very same minute the site went down, my self-hosted GitHub Actions runner went down too. Two unrelated programs dying together means the problem is not in either program.
First guess: a memory leak (wrong)
At first I suspected a memory leak in Next.js that ate all the RAM after three days. So I did two things:
- Upgraded Next.js to the latest version at the time
- Added a diagnostic line to my custom server that logs
process.memoryUsage()every 30 minutes
MEM rss=34.3MB heapUsed=32.7MB external=4.3MB arrayBuffers=0.5MB uptime=3.0h
After the upgrade the site still died every three days, and the MEM log showed memory staying flat right up to the end. No climb. It was not a leak. The process was running fine and then got terminated in an instant.
The real culprit
"Terminated in an instant" plus "exactly 72 hours" points at something external. I exported the task definition with schtasks /query /tn kbs0830_NextJS /xml, and the <Settings> block had no ExecutionTimeLimit element at all.
Not specified means the default: PT72H.
In Task Scheduler's "Create Task" dialog, the Settings tab has an option that is ticked by default: "Stop the task if it runs longer than: 3 days". For a one-off batch job that is a sensible safety net. For a website that is supposed to run forever, it means being killed every three days. The site and the runner were both scheduled tasks I had created the same way, so they died together.
The fix is to set the limit to 0 (no limit):
$s = New-ScheduledTaskSettingsSet -ExecutionTimeLimit ([TimeSpan]::Zero)
Set-ScheduledTask -TaskName kbs0830_NextJS -Settings $s
I thought it was fixed. It was not
I made exactly that change in September and wrote "fixed" in my notes. The October log kept going anyway: 10/07, 10/10, 10/13.
I exported the XML again: still no ExecutionTimeLimit. The most likely explanation is that the September Set-ScheduledTask ran in a PowerShell window without administrator rights. When I later re-ran the same line without elevation, it was indeed rejected (PermissionDenied 0x80070005). That is probably what happened in September too. I just did not notice the red line and assumed the change went through.
In the end I put all the task settings into one script, setup-autostart.ps1, ran it as administrator, and then exported the XML again. It only counts once I have seen <ExecutionTimeLimit>PT0S</ExecutionTimeLimit> with my own eyes.
Collateral damage
Each time the site went down, the watchdog brought it back within 5 minutes, so visitors probably never ran into it. Google's crawler did, though. In Search Console's crawl stats, nearly 20% of requests were "Server error (5xx)". Not all of that came from the 72-hour limit, since a tunnel outage happened in the same period, but those few-minute gaps certainly contributed. For a personal site that depends on search to be found, that hurts more than losing a few visitors.
What I learned
- A regular pattern in time is more useful than an error message. There was no exception to read here. Lining up the event times and seeing "every 3 days, 5 minutes later each time" is what exposed the cause
- When two unrelated things break at the same moment, look for what they share instead of fixing them separately
- "Fixed" has to be proven by reading the value back, not by "the command finished without an error", especially for system settings that need elevated rights
- When you create a scheduled task, remember to untick that default "3 days" box