Repository navigation
fix(fslock): handle temporary permission errors on Windows - #586
Conversation
…nding On Windows a deleted file stays "delete pending" until the deleting handle closes, and creating it again in that window fails with ERROR_ACCESS_DENIED (EPERM under Node) rather than ERROR_FILE_EXISTS. acquireMarker treated that as fatal, so a waiter could fail outright when the holder released the marker just as it retried. This flaked the Windows worker smoke test, where two Wasm runtimes contend on the credentials lock. Native dbc on Windows is affected too. On Windows hosts, retry permission errors from the create until the timeout (with a short grace so non-blocking attempts also ride out the window), then report the original error so genuine permission problems still surface. Add a regression test in which a rival holder takes and releases the marker in a tight loop; it fails within a few attempts without this change.
The grace for a delete-pending create was measured from the start of acquireMarker, so for any timeout of 250ms or more it was just the caller's deadline. That cut both ways: a waiter that saw the lock freed just before its deadline failed with a raw permission error instead of acquiring it, and a genuine access-denied error took the caller's whole timeout (10s for credentials) to surface. Start the grace at the first delete-pending failure, reset it on any other outcome, and leave it independent of the caller's timeout. As a deliberate trade-off, an acquire may now overrun its timeout by up to the 250ms grace, and a non-blocking attempt may block for that long, while a delete is pending. Add Windows tests that hold a marker delete-pending deterministically (classic disposition, kept open by a handle): one for a delete that clears within the grace, and one for an error that never clears, which fails against the previous code because it took the full timeout.
Two waiters that both find the same stale marker both remove it. On Windows the second delete can land while the first is still pending and fail with access denied, which removeDeadMarker reported as a hard error. Treat it like the marker already being gone: retry the create, which waits out the pending delete. There is no deterministic test: a delete-pending marker already fails the stat that precedes the remove, so the window between the two cannot be held open.
zeroshade
left a comment
There was a problem hiding this comment.
The fix is right and narrowly scoped: the Wasm build gets IsWindows from the JS host, and Windows ERROR_ACCESS_DENIED and Node's EPERM both count as fs.ErrPermission, so both builds are covered. The holdDeletePending helper is a nice deterministic way to reproduce the state. One design question and a few small things.
- The 250ms limit applies even when the caller asked to wait longer. A blocking caller with a 30s timeout still fails after about 250ms if the pending delete lasts longer. A pending delete lasts until every open handle to the file closes, not just the deleting one. That includes antivirus or the search indexer, the heartbeat's
Chtimes, and other waiters'os.Stat/os.ReadFileinremoveDeadMarker, and antivirus scans can easily take more than 250ms. For native callers,acquireMarkeronly runs after the OS lock in the same directory is held, so a lasting permission error on the marker is almost certainly a pending delete rather than a real permission problem. Suggestion: use the 250ms limit for non-blocking calls and the Wasm build, and let native blocking callers keep retrying until their own deadline.TestAcquireMarkerReportsPersistentPermissionErrorwould then need to use timeout 0 or the Wasm path. - The comment on
windowsDeleteMaybePendingsays "until the deleting handle closes"; it should be "until all open handles to it close". - The retry ignores
deadline, so a call can return up to 250ms after its timeout, and a non-blocking attempt can now block for up to 250ms. That's fine, but theacquireMarkerdoc comment should say so. - In
TestAcquireMarkerToleratesConcurrentRelease, the rival goroutine retries with no pause, keeping a CPU core busy for 2s. The test also runs on every non-Wasm platform, but only exercises the new code on Windows. I'd add a short sleep orruntime.Gosched()in the rival loop and shorten the run, or move the test tomarker_windows_test.go. - Edge case, not blocking: if another waiter wrongly removes our marker as stale while we still hold it, our release's
os.Removecan hit the same permission error and report it as a release failure. Treating that error likeErrNotExistin the release would fit the existing "must not remove another holder's marker" behaviour.
… Windows Revert before merge.
|
Thanks @zeroshade. I've pushed fixes and am testing that we still get the failure on CI. I'll request review again when this is ready. |
|
CI fails with the new tests and without the fixes in https://github.com/columnar-tech/dbc/actions/runs/43998520925/job/133756480248?pr=586. Reverting. |
… fail on Windows" This reverts commit 09b1454.
zeroshade
left a comment
There was a problem hiding this comment.
Thanks, all five addressed. Splitting on holdsOSLock is the right shape: native callers wait out a long delete-pending until their own deadline and report contention, while the Wasm path keeps the bounded grace and reports a real permission error. The doc comment now covers the grace overrun, the release tolerates a pending delete, and the concurrent-release test no longer pins a core. Nice touch confirming the new Windows tests fail without the fix. LGTM.
This PR fixes a transient error that should only be possible on Windows and affects both dbc's native and Wasm builds. The bug was introduced in #551.
The error we got in CI which led us to this was,
The cause is that we use a filesystem lock here and, on Windows, there's a very brief period after a file delete where trying to create a new file at that path returns a permissions error instead of a file exists error due to the handle still being held. The fix is to retry gaining the lock on such errors for an extra 250ms.