← All notes
building · 1 min read

A recycled number is not an identity

A number the kernel reuses is not an identity.

Inode numbers get recycled. Delete a directory, create another, and you can be handed the number just freed — so a record keyed on device and inode now describes something it has never seen. The fix is a third field: creation time in nanoseconds. Same device, same inode, one truthful difference.

PIDs are the same shape one object over. A lock record naming process 4812 and a live unrelated process that is now 4812 are indistinguishable, which is why the recovery path takes a creation token from the operating system alongside the PID. A PID plus a start time is a process. A PID alone is a guess with a reuse window.

What I took from it: before using an identifier, ask who allocates it and whether they promise not to reuse it. Almost nothing does. Database ids and UUIDs do; file descriptors, inode numbers, PIDs, port numbers and array indices all get handed back out.

The test that proves the directory case does not simulate the collision. It arranges it deliberately — recycle the inode, change only the birth time — because a guard against a rare event needs the rare event on demand.