Christophs Weblog

Vierundzwanzig sind zu wenig

Race Condition mkdir vs. find -delete

A clean-up script on one of our servers threw the following error yesterday:

find: WARNING: Hard link count is wrong for `privatpath‘ (saw only st_nlink=28
but we already saw 26 subdirectories): this may be a bug in your file system driver.
Automatically turning on find’s -noleaf option. Earlier results may have failed to include
directories that should have been searched.

At a first glance it looks like a file system or kernel issue but in our case it wasn’t … It turned out to be a simple race condition between „find“ looking at a directory structure and „mkdir“ creating new directorys.

I could easily reproduce the Warning by running:

for i in $(seq 1 100000); do mkdir /tmp/cp-test/folders/$i; done

and

cd /tmp/cp-test/folders
nice find -mindepth 1 -delete

at the same time. At one stage find complained:

find: WARNING: Hard link count is wrong for `.‘ (saw only st_nlink=6280 but we already saw 6278 subdirectories): this may be a bug in your file system driver. Automatically turning on find’s -noleaf option. Earlier results may have failed to include directories that should have been searched.

Actually I manually restarted the find over and over again while the mkdir was running. Eventually the mkdir will complain about „mkdir: cannot create directory `/tmp/cp-test/folders/99995′: Too many links“ which doesn’t matter.

I did the tests on a SLES 11 SP2, running in an vmware virtualization environment using SAN disks.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

Christophs Weblog © 2016