← Today I learned

The second time my pool suspended, zpool clear made it worse

A couple of weeks ago I wrote about my ZFS pool being suspended for 17 hours after its USB enclosure dropped off. I added alerts, and zpool clear brought the pool back. Then it happened again, and this time zpool clear couldn't save it.

It wasn't the load

Last time the enclosure dropped during a scrub, so I blamed sustained load. This time the pool was idle: no scrub, no backup running, and the UPS reported clean power. So now I suspect the enclosure's own power or sleep handling, not the disks or the workload.

ZFS doesn't notice missing disks until it reads them

The enclosure dropped at 8:53 p.m. ZFS kept calling the pool ONLINE until something tried to read from it 54 minutes later. Only then did it suspend the pool, and only then did my health check (which asks ZFS) send the alert.

Why clear didn't work this time

After I power-cycled the enclosure, the disks came back under new device names (sdg–sdj instead of sdk–sdn), and the old names were never freed. I ran:

zpool clear tank

The pool resumed, retried its I/O, and every write failed instantly with error 6 (ENXIO, "no such device"). ZFS was still holding the old, dead device handles instead of finding the disks again by partition UUID. The pool suspended again, and this time zpool clear itself hung in uninterruptible sleep (state D). Every zpool command after that queued up behind it and hung too. Meanwhile one CPU core sat at 100%.

The disks were fine: SMART was clean, and reading them directly ran at 155 MB/s. The only fix left was a reboot.

The reboot hung too

A container still had processes stuck on the pool, so the shutdown couldn't stop it. Even systemctl reboot --force left a machine that answered ping but had no SSH. I had to hold the power button.

It came back cleanly: both pools ONLINE, 0 errors. Like last time, the scary data-error count was just I/O that failed while the disks were gone.

What I'd do next time

  • If zpool clear hangs or the retried I/O fails right away, stop. Don't run more zpool commands; each one just adds another hung process.
  • Flush the healthy filesystems (sync -f /path/on/each/pool), then go straight to a hard reset. A soft reboot can't finish while processes are stuck on the dead pool.

Checking for missing disks without asking ZFS

To catch it in minutes instead of an hour, my 5-minute health check now looks for the disks itself before it makes any zpool call. Checking whether a file exists can't hang, even when ZFS is wedged. Roughly:

# While the pool is healthy, remember its data disks (leave out cache and log devices)
zpool status -P tank | awk '$1 ~ "^/dev/disk/by-partuuid/" {print $1}' > /var/lib/tank.disks

# Every 5 minutes, before touching ZFS
missing=0
while read -r disk; do
  [ -e "$disk" ] || missing=$((missing + 1))
done < /var/lib/tank.disks

if [ "$missing" -gt 0 ]; then
  curl -fsS -m 15 -H @/etc/ntfy-token.header -H "Priority: urgent" \
    -H "Title: Enclosure disconnected" \
    --data-binary "$missing disks missing from tank" https://ntfy.example/alerts
fi

Now the alert reaches my phone within about five minutes of the enclosure dropping, often before ZFS has noticed anything.