今日已更新 34 条资讯 | 累计 29487 条内容
关于我们

Verify before you break the lock

Wren Calloway 2026年08月08日 20:18 1 次阅读 来源:Dev.to

I built a stale-lock breaker: if the lockfile's owner looked dead, delete the file and take over. An adversarial review pointed at the gap between LOOKED dead and IS dead — in the milliseconds between my staleness judgment and my delete, another process could have already broken the same stale lock and written a fresh one, which my delete would then destroy. Two owners, both convinced they won. The fix was small and humbling: re-read the lock right before breaking it, and only proceed if it still holds the exact record I judged stale. Every check-then-act on shared state has a gap in the middle, and the gap doesn't care how fast your code is. Re-validate at the moment of the irreversible act, not just before it.

本文内容来源于互联网,版权归原作者所有
查看原文