fix: prevent EPERM on delete/organize when video is still playing#92
Merged
Conversation
…ld by the player On Windows, open fs.createReadStream handles (from the video player's HTTP range requests) block fs.unlinkSync and fs.renameSync with EPERM. - VideoPlayer now pauses and removes the video src (triggering stream abort and handle release) before calling onDelete or starting organize - deleteFile() is async and uses waitForUnlock + unlinkWithRetry so any residual timing gap between the browser abort and OS handle release is handled with retries instead of a hard failure - Auto-delete paths in fileManager.js (deleteFullRecording after organize) replaced bare fs.unlinkSync with the existing unlinkWithRetry helper Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
deleteFile() is now async so all call sites must await it: - apiServer.js: 3 places (clips/delete, recordings/delete, delete-batch) - recordingService.test.js: 6 tests updated to async/await Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
runAutoDelete called deleteFile() without await, getting a Promise instead of the result object. Made runAutoDelete async, updated fire-and-forget callers in main.js and watcherHandlers.js to use .catch(), and converted all runAutoDelete unit tests to async/await. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
<video>src (closing the browser's HTTP range-request stream) before callingonDeleteor starting organize — this releases thefs.createReadStreamhandle on the main process side before any filesystem operation is attempteddeleteFile()inrecordingService.jsis now async and wraps the unlink withwaitForUnlock(4 × 500ms) +unlinkWithRetry(4 × 500ms), catching any residual gap between the browser aborting its stream and the OS releasing the handlefileManager.js(deleteFullRecordingafter organize, two sites) replaced barefs.unlinkSyncwith the existingunlinkWithRetryhelper, consistent with every other deletion in that fileRoot cause
On Windows,
fs.createReadStreamholds an OS file handle for each range request the browser's<video>element makes while buffering.fs.unlinkSyncandfs.renameSyncfail withEPERMwhile those handles are open. The failure was intermittent because it depended on whether a range request happened to be in-flight at the exact moment the user triggered delete or organize.Test plan
🤖 Generated with Claude Code