← DevLog

3 min read

The nightly restart that killed every long import

A full product import takes most of a day. The server restarts itself at night when updates need it. The import died with no error, and the next one refused to start while reporting success.

A full product import on one shop takes 21 to 24 hours: about 1,600 product families at roughly 50 seconds each. One run stopped after nine hours and 45 minutes, at family 633. No error. No exit line. No stack trace. The log simply ended.

The first cause: a reboot

The server had rebooted at 01:00. The hosting provider reboots its machines at that time when updates require it, not every night. That is why it was hard to see: four reboots in a row, then nothing for nine days, then another.

Nothing a process does survives a reboot. Running the import under nohup or setsid does not help. And an import that takes 21 to 24 hours cannot avoid 01:00 unless it starts right after one.

How to tell a reboot from your own process crashing:

last -x reboot | head -5
uptime

Other tells: the user service manager has a tiny uptime and a low process ID on a host that has been up for days, and the file cache in memory has collapsed to almost nothing.

The second cause: a restart without a reboot

A few weeks later the hourly update import kept dying, at 00:40, while the server stayed up. This time a system timer was checking every night whether running services used outdated libraries, and restarting them if so. It restarted the whole application stack in about five seconds: database, web server, search, queue workers. The import was killed in the middle of a query.

The provider moved the timer to 01:00 and added a dry run. Which fixes nothing for an import that runs at 01:00.

The part that turned one failure into a lost night

A killed import leaves its job marked as running. Every import after it checks that marker, sees a job in progress and refuses to start. The command then exits with status 0, as if it had worked.

So the monitoring saw a successful run every hour. The product sync was in fact dead for eight to eleven hours a night, until someone noticed and cleared the marker by hand. I wrote about that exit code before. This is how it hurts in practice.

What helps

  • Ask your host when they reboot and restart services, in writing, for every server. In this case the timers differed per machine.

  • Never let a job lock live forever. Release it when the job has made no progress for, say, three hours, and send a mail when that happens. Progress means new log lines, not a process ID that a restart can reuse.

  • Alert on what the import achieved, not on its exit code. A normal hour has eight to ten import runs. An hour with none is the alarm.

  • Make long imports resumable, or split them, so a restart costs an hour instead of a day.

None of these failures produced an error message. That is the common thread: the server did what it was configured to do, the import did what it was written to do, and the shop quietly ran on stale product data.