Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release file handle when opening new file #272

Closed
cdalexndr opened this issue Mar 10, 2020 · 39 comments
Closed

Release file handle when opening new file #272

cdalexndr opened this issue Mar 10, 2020 · 39 comments

Comments

@cdalexndr
Copy link

Open file, open new file, try to delete old file => file is till opened in LoselessCut

@mifi
Copy link
Owner

mifi commented Mar 19, 2020

I assume this is on windows, right?

@cdalexndr
Copy link
Author

Yes, Windows 10

@mifi
Copy link
Owner

mifi commented Mar 26, 2020

I just tested on Windows 8.1 and it works there.

  1. drag drop a file from my desktop into losslesscut
  2. drag drop another file from my desktop (choose open instead)
  3. right click the first file on my desktop and delete it
  4. success

Is this the same as you did?

@cdalexndr
Copy link
Author

Just reproduced with:

  1. Open file
  2. Select segments and export
  3. File -> Close
  4. App is still running
  5. Try to delete old file

@cdalexndr
Copy link
Author

It seems it doesn't reproduce every time...

@cdalexndr
Copy link
Author

Reproduce it again with a ~3h video with 18 segments reduced to ~1h30m

@mifi
Copy link
Owner

mifi commented Apr 3, 2020

When delete gives an error, maybe you could check which process is holding the file open
Whether it is ffmpeg, ffprobe or LosslessCut itself.
https://superuser.com/questions/117902/find-out-which-process-is-locking-a-file-or-folder-in-windows

@cdalexndr
Copy link
Author

LosslessCut.exe has the file handle blocking delete.

@mifi
Copy link
Owner

mifi commented Apr 11, 2020

I tried again now with the newest version and I'm still not able to reproduce this problem on Windows 8.1. I can even trash the file while it is open in LosslessCut. Could it be some stricter settings in your operating system configuration?

@cdalexndr
Copy link
Author

cdalexndr commented Apr 11, 2020

Forgot to check what version I'm using. It's 3.13.0.0.
I'll try newest version and report back if it's still a problem.

@cdalexndr
Copy link
Author

With 3.19.0, the file handle remains open in ffprobe.exe, but it gets released after some time.
I guess there is still pending work for ffprobe.

@cdalexndr
Copy link
Author

Also managed to reproduce stuck file handle in LoselessCut that doesn't get released.
Same as before, it doesn't reproduce every time.

@mifi
Copy link
Owner

mifi commented Apr 18, 2020

How long do you try to wait before checking the file handle? Does it get released after some time? I know that Windows has a lot of issue with file locking in general compared to MacOS/Linux which doesn't have a concept of locking files.

@mifi mifi added the bug label Apr 18, 2020
@cdalexndr
Copy link
Author

If it's locked by ffprobe.exe it gets released after some time (not much, ~1min).
If it's locked by LoselessCut it doesn't get released and I have to quit the program for the file handle to be released.

@mifi
Copy link
Owner

mifi commented Apr 18, 2020

Ok. Do you see any other patterns? Like did it ever happen from just opening a file and then closing it? Or do you have to cut first for this to happen? Does it happen with only some file types?

@cdalexndr
Copy link
Author

Just reproduced file handle stuck temporary by ffprobe.exe and also permanently by LoselessCut 3.19.0 with:

  1. Open file
  2. Browse timeline
  3. File -> Close
  4. Cannot delete file

So the editing has nothing to do with file handle getting stuck.
Files are .mkv, 2-3 GB size.

@MisterReally
Copy link

I am experiencing the same issue consistently.

Windows 10 Enterprise
LosslessCut 3.39.0 (Built locally - not installed from Windows Store)

Clicking the trash icon after editing file of size 433,373 KB displays the following messages in 'Developer Tools' view (I replaced some file path values with a string enclosed with <> for privacy):

react_devtools_backend.js:4049
react_devtools_backend.js:4049
trashResponse
{tmpFiles: true, projectFile: true, sourceFile: true}

Command failed: C:\Users<acsii_string>\AppData\Local\Temp\7dd5c8b8-fe4c-41ff-bda7-7f7313e0caad.tmp.exe D:<ascii_string><ascii_string> 2021-10-12 15_04-cap.mp4

at ChildProcess.exithandler (child_process.js:308)
at ChildProcess.emit (events.js:210)
at maybeClose (internal/child_process.js:1021)
at Process.ChildProcess._handle.onexit (internal/child_process.js:283)

A dialog appears with message: "Unable to move file to trash. Do you want to permanently delete it?

User then selects button labeled "Permanently delete" and receives the following exceptions:

Error: ENOENT: no such file or directory, unlink ' D:<ascii_string><ascii_string> 2021-10-12 15_04-cap-proj.llc'
overrideMethod @ react_devtools_backend.js:4049
Promise.catch (async)
(anonymous) @ main.36c952cf.chunk.js:1
async function (async)
(anonymous) @ main.36c952cf.chunk.js:1
Ve @ 2.02f77fbb.chunk.js:2
Ke @ 2.02f77fbb.chunk.js:2
(anonymous) @ 2.02f77fbb.chunk.js:2
Cr @ 2.02f77fbb.chunk.js:2
wr @ 2.02f77fbb.chunk.js:2
(anonymous) @ 2.02f77fbb.chunk.js:2
Le @ 2.02f77fbb.chunk.js:2
(anonymous) @ 2.02f77fbb.chunk.js:2
Ir @ 2.02f77fbb.chunk.js:2
Jt @ 2.02f77fbb.chunk.js:2
Zt @ 2.02f77fbb.chunk.js:2
t.unstable_runWithPriority @ 2.02f77fbb.chunk.js:2
Vi @ 2.02f77fbb.chunk.js:2
Pe @ 2.02f77fbb.chunk.js:2
Qt @ 2.02f77fbb.chunk.js:2

react_devtools_backend.js:4049 Error: EBUSY: resource busy or locked, unlink ' D:<ascii_string><ascii_string> 2021-10-12 15_04-cap.mp4'
overrideMethod @ react_devtools_backend.js:4049
(anonymous) @ main.36c952cf.chunk.js:1
async function (async)
(anonymous) @ main.36c952cf.chunk.js:1
Ve @ 2.02f77fbb.chunk.js:2
Ke @ 2.02f77fbb.chunk.js:2
(anonymous) @ 2.02f77fbb.chunk.js:2
Cr @ 2.02f77fbb.chunk.js:2
wr @ 2.02f77fbb.chunk.js:2
(anonymous) @ 2.02f77fbb.chunk.js:2
Le @ 2.02f77fbb.chunk.js:2
(anonymous) @ 2.02f77fbb.chunk.js:2
Ir @ 2.02f77fbb.chunk.js:2
Jt @ 2.02f77fbb.chunk.js:2
Zt @ 2.02f77fbb.chunk.js:2
t.unstable_runWithPriority @ 2.02f77fbb.chunk.js:2
Vi @ 2.02f77fbb.chunk.js:2
Pe @ 2.02f77fbb.chunk.js:2
Qt @ 2.02f77fbb.chunk.js:2

@mifi
Copy link
Owner

mifi commented Nov 3, 2021

I think it may be related to this chromium bug:
https://bugs.chromium.org/p/chromium/issues/detail?id=969049

i suspect that it happens when first opening a natively supported file (which creates a <video> tag. Then if later opening a not natively supported file the <video> tag is automatically removed by React but the video is still open in chromium due to that bug. It may have been fixed in newest chromium/electron, but we are being held back from upgrading electron due to macos issues #714

Update:
Seems that chromium bug is fixed already: https://bugs.chromium.org/p/chromium/issues/detail?id=1064749

And I don't think it's what's causing it because <video> is actually never removed from the dom in losslesscut

@aCuria
Copy link

aCuria commented Feb 25, 2022

Same issue with Windows 11, Lossles Cut v3.4.3

"Trash Can" function also does not work for deleting original file

maybe we can have some hack to "restart" the program when the trash can button is hit...

@mifi
Copy link
Owner

mifi commented Feb 25, 2022

@aCuria do you see which program is locking the file? Is it losslesscut.exe or is it ffprobe.exe ? and if you wait for a few minutes, will it resolve?
Also is the file natively supported or converted to supported format?

@aCuria
Copy link

aCuria commented Feb 26, 2022

do you see which program is locking the file?

Error message windows gives is "The action can't be completed because the file is open in LosslessCut"

Is it losslesscut.exe or is it ffprobe.exe ?

ffprobe process does not appear to be running in the task manager

and if you wait for a few minutes, will it resolve?

Not after 5min, and losslesscut cpu usage is at 0% all the way

Also is the file natively supported or converted to supported format?

converted

mifi added a commit that referenced this issue Feb 26, 2022
@mifi
Copy link
Owner

mifi commented Feb 26, 2022

I did some improvements to the Canvas player (unsupported files player) that will hopefully resolve this in the next version

@mifi
Copy link
Owner

mifi commented Mar 13, 2022

Would be nice to see whether the newest version has improved this situation

@aCuria
Copy link

aCuria commented Mar 17, 2022

No change in v3.44...

The bug seems to be related to not closing the original file after proxy generation

@mifi
Copy link
Owner

mifi commented Mar 18, 2022

Is it still LosslessCut.exe holding the file handle, or is it ffmpeg.exe or ffprobe.exe? And does the handle get released after some seconds/minutes?

@aCuria
Copy link

aCuria commented Mar 29, 2022 via email

@mifi
Copy link
Owner

mifi commented Mar 29, 2022

Thank you. Then I honestly don’t know what’s causing it but hopefully after upgrading Electron to the latest version it will be solved.

@mikeyaworski
Copy link
Contributor

I've been using release 3.44.0 and still run into this issue. The way I find myself running into it either exporting + deleting videos in a large batch, or exporting videos that are large in size. My typical workflow might be:

Large batch:

  • Open a batch of 20-40 files
  • Go through each one, export a portion of it, then delete it
  • At some point, deleting one of them will fail

Large videos:

  • Exporting part of a movie (mp4 or mkv) and then deleting

It seems extra likely for deleting to fail if you leave lossless cut open in the background for a while, and then come back to it. This may or may not be true.

@mifi
Copy link
Owner

mifi commented May 21, 2022

What's useful to observe in order for me to fix this:

  1. Is it LosslessCut.exe, ffprobe.exe or ffmpeg.exe holding the file lock?
  2. Does the file get released/unlocked after a few minutes?

If 2 is true, it might be possible to workaround this issue by having losslesscut continuously retrying to delete the file in a while-try-catch loop for a few minutes after the delete button is pressed, to remedy these issues on windows.

@mikeyaworski
Copy link
Contributor

  1. The Windows prompt says LosslessCut. I'll look closely next time it happens and update this thread.
  2. I don't believe so. I've been working my way through 40 files in a batch before, where one of the first gets locked, and even once I've gone through the rest of the batch, the first is still locked. I'll do a test for this the next time it happens though.

@mifi
Copy link
Owner

mifi commented May 22, 2022

If it never gets released and it's LosslessCut.exe that's holding the file handle (and you see no ffmpeg.exe or ffprobe.exe processes in Task Manager), then that's probably an electron bug and nothing I can do about it, but it might be fixed once we upgrade electron to the newest version #714

@mikeyaworski
Copy link
Contributor

Writing to confirm that there are no ffmpeg or ffprobe processes in task manager, and it never gets released.

And for clarification, I try to delete the file from within LosslessCut (the d shortcut), and it says it's unable to move the file to trash. I then try to delete it with the Windows File Explorer and it says "The action can't be completed because the file is open in LosslessCut"

@mifi
Copy link
Owner

mifi commented May 28, 2022

Even after opening a new file, llc still holds the handle to the old file indefinitely? I hope this will be fixed when we upgrade electron

@mikeyaworski
Copy link
Contributor

Yes it does. I need to close LosslessCut before I'm able to delete the file.

@mifi
Copy link
Owner

mifi commented Jun 4, 2022

Update: seems to be a problem also on MacOS, although less visible #1179

@mifi mifi mentioned this issue Jun 4, 2022
@fade0ff
Copy link

fade0ff commented Sep 8, 2022

I have a similar problem in Win10 and version 3.46.2 . After exporting a cut version with embedded JPEG, and closing the file with Ctrl+W (or File->Close) I'm regularly unable to delete the original file unless I close LosslessCut. I if use ResMon or Process Explorer to search for the blocking handler, both report LosslessCut.exe twice (!).
These locks also don't disappear after some minutes. The only way to delete the file is to close LosslessCut.
Locks pretty much like the input file handle is not released properly.
This seems to be only a problem for bigger files though. I.e. I can't really reproduce this issue for smallish MP4s, but for those close to 1GB, it seems to happen absolutely every time.

@mifi
Copy link
Owner

mifi commented Nov 23, 2022

If you can try again with the newest version that'd be great. now upgraded to electron 21.

@fade0ff
Copy link

fade0ff commented Nov 23, 2022

I tried some larger files with 3.48.2 beta and closing them with Ctrl-W after exporting seems to release the file handle immediately and I can e.g. delete the original file -> seems to work for me. Thanks!

@mifi
Copy link
Owner

mifi commented Nov 24, 2022

great! I'll close this and we can reopen if it's still a problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants