-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Weird binary file lock with PublishSingleFile=true #1260
Comments
This issue should be moved to the https://github.com/dotnet/runtime repo. The runtime host doesn't explicitly take a lock on itself. |
@swaroop-sridhar thanks for the link. runtime/src/installer/corehost/cli/apphost/bundle/runner.cpp Lines 42 to 64 in bcd203d
Note that map_host is always called, but unmap_host is only called when the extraction cannot be reused. Still doesn't tell why the behavior is different depending on which OS you're using, but we'll get there.As you can see below, the map_host function calls pal::map_file_readonly :runtime/src/installer/corehost/cli/apphost/bundle/runner.cpp Lines 15 to 17 in bcd203d
This map_file_readonly function has multiple source codes.For Unix: runtime/src/installer/corehost/common/pal.unix.cpp Lines 60 to 89 in 1d5123f
And for Windows: runtime/src/installer/corehost/common/pal.windows.cpp Lines 79 to 117 in 1d5123f
As you can see, the Unix version closes the file reader before returning on the last branch, while the Windows version doesn't. Now we know the cause of this inconsistent behavior. Possible solution A: change the pal.windows::map_file_readonly function to close the file before returning on the last branch.Possible solution B: change the runner_t::extract function to call unmap_host before returning on the first branch.Hope it helps. |
Thanks a lot for the detailed analysis @Logerfo. I'll fix the issue, Thanks. |
Is there an ETA on when this fix will be merged in a public release? Sorry to bring it up, but I'm not familiar with the runtime's update flow compared to dotnet/core and can't seem to find any relevant information. It's a bit of an annoying blocker and seems like a minor change that can get pushed through. |
I'll port the change to CoreCLR repo for patching to 3.1 this week. I expect it'll make into March or April servicing release. |
dotnet/runtime#1260 A single-file app cannot be renamed while running -- an idiom used while updating the app in-place. When running a single-file app, the AppHost reads itself in order to extract the embedded contents. The Apphost must always read its contents in order to read the headers, but doesn't always extract the contents, because previously extracted files are re-used when available. In the case where apphost doesn't extract, currently, the file stream isn't immediately closed on Windows. This prevents the app from being renamed while running. This change fixes the problem by closing the open stream in all cases. Very Low dotnet/runtime#2272
dotnet/runtime#1260 A single-file app cannot be renamed while running -- an idiom used while updating the app in-place. When running a single-file app, the AppHost reads itself in order to extract the embedded contents. The Apphost must always read its contents in order to read the headers, but doesn't always extract the contents, because previously extracted files are re-used when available. In the case where apphost doesn't extract, currently, the file stream isn't immediately closed on Windows. This prevents the app from being renamed while running. This change fixes the problem by closing the open stream in all cases. Very Low dotnet/runtime#2272
dotnet/runtime#1260 A single-file app cannot be renamed while running -- an idiom used while updating the app in-place. When running a single-file app, the AppHost reads itself in order to extract the embedded contents. The Apphost must always read its contents in order to read the headers, but doesn't always extract the contents, because previously extracted files are re-used when available. In the case where apphost doesn't extract, currently, the file stream isn't immediately closed on Windows. This prevents the app from being renamed while running. This change fixes the problem by closing the open stream in all cases. Very Low dotnet/runtime#2272
Any update on this making it to release @swaroop-sridhar ? It's still a blocker for us for self-updating apps. It looks to be slated for the 3.1.4 servicing release? |
This change will be in this month's 3.1.4 release. Thanks. |
Background
Hello.
I have a quite unusual scenario where my application would like to move its own binary while running. On linux, I'm free to do anything I want with currently running binary, including moving it. On Windows, at least usually, I'm not able to delete the running binary, but I'm still able to move it, which satisfies my usage.
Issue
I've noticed inconsistency in regards to this when using
PublishSingleFile=true
. Ideally I'd like to keep being able to move the binary away, which I use right now with no further issues.In particular, this is what happens (only on Windows):
PublishSingleFile=true
project for the first time, or after you've manually cleaned%TEMP%\.net
, the app unpacks itself and you're free to rename/move the binary as you please.If anything, I'd expect this behaviour to be consistent, or logically, more restrictive when we unpack for the first time, rather than when re-using existing structure. Instead, it's entirely different, to the point that makes me believe it's something worth reporting or getting more details about.
Of course, judging by the above, the "workaround" for my use case is manually cleaning
%TEMP%\.net
after each program run, which is a very weird solution, but a working one. I'm not entirely sure why the application would hold exclusive file access when re-using the existing structure but not when unpacking for the first time, which is exactly why I've decided to create this issue.Ideally it'd be nice if that lock wasn't needed (so I could keep using my planned use case), but in case you actually have reasoning for it, you'd likely want to keep it up for both cases and not only one that is effectively a subset of operations (run) in another one (unpack and run). In any case, at least in my opinion, it's something worth investigating and deciding whether that exclusive file lock could be released (like when run for the first time), or if it's actually needed in both cases (in which case you might want to add it to first run as well).
Thank you in advance for your time in regards to this isssue.
The text was updated successfully, but these errors were encountered: