How a Rotated Log File Nobody Closed Filled a 100 GB Disk That du Said Was Mostly Empty
← Back
November 27, 2026Infrastructure8 min read

How a Rotated Log File Nobody Closed Filled a 100 GB Disk That du Said Was Mostly Empty

Published November 27, 20268 min read

02:17 UTC. PagerDuty: disk_used_percent > 95 on api-edge-02, then 98, then 100 at 02:31. The first write error shows up in Datadog at 02:33: ENOSPC: no space left on device.


the scramble

I get paged because I own the service. The on-call is a teammate who is three weeks into the rotation. He posts in the incident channel: "disk is full, deleting old stuff". Reasonable instinct, wrong move, and I don't know that yet.

The box is a single EC2 instance running a Node API behind an ALB, with a 100 GB root volume. Requests that need to write a temp upload are failing with 500s, about 9 percent of traffic at 02:40. Health checks still pass, so the ALB keeps sending traffic.

First theory: a traffic spike produced a lot of upload temp files. He checks.

$ df -h / Filesystem Size Used Avail Use% Mounted on /dev/nvme0n1p1 100G 100G 0 100% / $ sudo du -xsh / 38G /

That is the part that makes me sit up. df says 100 GB used. du says the entire filesystem holds 38 GB. Sixty-two gigabytes are charged to the volume and not visible in any directory.

the hunt

Dead end one: inodes. A volume can report full when it runs out of inodes, even with free blocks.

$ df -i / Filesystem Inodes IUsed IFree IUse% Mounted on /dev/nvme0n1p1 6553600 412880 6140720 7% /

7 percent. Not that.

Dead end two: the docker overlay. We do not run the API in Docker on this host, but the host has a leftover Docker install from an old experiment. du -x stays on one filesystem, so if /var/lib/docker were a separate mount it would be skipped. I run docker system df. 1.2 GB. Not that either.

Dead end three: another mount hiding data underneath. If something was written to /var/log before a volume was mounted on top of it, du cannot see the files. I check mount and the fstab. There is one extra mount, /data, and it was mounted at boot. No shadowed directory.

At this point, 02:58, the teammate has deleted 4 GB of old upload temp files. df still says 100 percent, with Avail at 3.9 GB for about a minute, and then 0 again. Something is consuming space as fast as we free it, and it is not showing up in du.

That combination, df larger than du and growing, has one common explanation: a file that has been unlinked but is still open. Deleting a file only removes its name from a directory. The blocks are freed when the last open file descriptor closes. If a process still has the file open, the space stays charged and the file is invisible to du.

$ sudo lsof +L1 | awk 'NR==1 || $7 > 1000000000' COMMAND PID USER FD TYPE DEVICE SIZE/OFF NLINK NODE NAME node 2841 app 1w REG 259,1 65748312064 0 1310811 /var/log/api/app.log.1 (deleted)

+L1 lists open files with a link count below one, meaning deleted. There it is: PID 2841, our API, file descriptor 1, 65.7 GB, name /var/log/api/app.log.1 (deleted).

the find

Our Node process logs by writing to stdout, and systemd's unit redirects stdout to a file:

# /etc/systemd/system/api.service [Service] ExecStart=/usr/bin/node /srv/api/server.js StandardOutput=append:/var/log/api/app.log StandardError=append:/var/log/api/app.log

And logrotate had this config, which someone copied from the nginx example three months ago:

# /etc/logrotate.d/api /var/log/api/app.log { daily rotate 3 compress delaycompress missingok notifempty }

Without copytruncate, logrotate renames app.log to app.log.1 and creates a fresh empty app.log. Nginx's example config works because it has a postrotate block that sends USR1 so nginx reopens its log files. We had no such block, and Node would not have reopened anything on USR1 anyway (it starts the inspector). The process kept its descriptor on the inode that was now named app.log.1.

Renaming alone does no harm. Each night the same inode moved down the chain: app.log.1, then .2, then .3, still growing, still visible to du. The trouble started on the fourth night. With rotate 3, logrotate deleted that file. The process never noticed, because it was still writing to the original inode. From then on every log line went into a file with no name. The bytes were real, du could not see them, and nothing would ever rotate them.

The numbers fit. The API logs about 7.6 MB per minute at normal traffic, which is roughly 11 GB a day. Six days of that is 65 GB. The disk crept up for six days without crossing the alert line, until a Monday morning batch of uploads pushed it to 100.

the fix

Immediate: free the space without restarting the process, since a restart would drop in-flight requests during the incident. You can truncate a deleted-but-open file through the proc filesystem:

$ sudo truncate -s 0 /proc/2841/fd/1 $ df -h / Filesystem Size Used Avail Use% Mounted on /dev/nvme0n1p1 100G 39G 61G 39% /

Avail jumped from 0 to 61 GB at 03:12. The 500s stopped within 20 seconds.

Permanent: two changes. First, the logrotate config now uses copytruncate, which copies the log and truncates the original in place, so the descriptor stays valid:

# /etc/logrotate.d/api /var/log/api/app.log { daily rotate 7 compress delaycompress missingok notifempty copytruncate }

copytruncate has a small window where lines written between the copy and the truncate are lost. For application logs that also go to Datadog, that is acceptable. The process was also writing to the file in append mode (append: in the unit), which matters: with plain truncation, a writer that is not in append mode would keep its old offset and leave a sparse file full of zeros. systemd's append: avoids that.

Second, we stopped writing the file at all. The unit now sends stdout to the journal and the Datadog agent tails that, with journald capped:

# /etc/systemd/journald.conf.d/limits.conf [Journal] SystemMaxUse=4G MaxRetentionSec=7day

the aftermath

Impact: about 9 percent of requests failed with 500 for 56 minutes, from 02:33 to 03:12 plus the tail while alerts were being understood. By our logs that is roughly 1,900 failed requests, of which 310 were upload attempts that users had to repeat. No data was lost.

What changed:

  • Collecting df minus du as a metric is awkward, so we alert on the rate of growth instead: more than 5 percent of the volume in six hours pages us, regardless of the absolute level.
  • A nightly check runs lsof +L1 and reports any deleted file over 500 MB to Slack.
  • The runbook for disk-full now starts with df versus du before deleting anything. Deleting files while a deleted file is the problem only wastes the first 30 minutes.
  • The other three hosts using the copied logrotate snippet were fixed the same day. One of them had 19 GB of invisible log already.

What I took from it: when df and du disagree by more than a few percent, stop looking for files. The space is held by a process, and lsof +L1 will name it.

Share this
← All Posts8 min read