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/6.0] SafeFileHandle.Unix: don't DeleteOnClose when lock is not successful. #60112

Merged
merged 2 commits into from
Oct 8, 2021

Conversation

tmds
Copy link
Member

@tmds tmds commented Oct 7, 2021

Description

In #55153 DeleteOnClose handling moved from FileStream to SafeFileHandle.

This unintentionally caused DeleteOnClose to be applied even when FileShare locking fails. As on Windows, DeleteOnClose should not take effect when sharing prevents the file from being opened.

This also swaps the order of unlink and LOCK_UN in Dispose as it was prior to #55153.
Either order should be fine.

Customer impact

Unintentional deleting of file.

Testing

Existing and new unit test.

Risk

Low. Behaves the same as previous versions of .NET.

Fixes #59995.

In dotnet#55153 DeleteOnClose handling
moved from FileStream to SafeFileHandle.

This unintentionally caused DeleteOnClose to be applied even when
FileShare locking fails. As on Windows, DeleteOnClose should not take
effect when sharing prevents the file from being opened.

This also swaps the order of unlink and LOCK_UN in Dispose as it was
prior to dotnet#55153.
Either order should be fine.
@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Oct 7, 2021
@ghost
Copy link

ghost commented Oct 7, 2021

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Issue Details

In #55153 DeleteOnClose handling
moved from FileStream to SafeFileHandle.

This unintentionally caused DeleteOnClose to be applied even when
FileShare locking fails. As on Windows, DeleteOnClose should not take
effect when sharing prevents the file from being opened.

This also swaps the order of unlink and LOCK_UN in Dispose as it was
prior to #55153.
Either order should be fine.

Fixes #59995.

@stephentoub @dotnet/area-system-io ptal.

This targets release/6.0 branch. It is a subset of changes from #55327 which tackles a broader issue.

Author: tmds
Assignees: -
Labels:

area-System.IO

Milestone: -

Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, big thanks for the fix @tmds!

@tmds tmds changed the title SafeFileHandle.Unix: don't DeleteOnClose when lock is not succesful. [release/6.0] SafeFileHandle.Unix: don't DeleteOnClose when lock is not succesful. Oct 8, 2021
@tmds
Copy link
Member Author

tmds commented Oct 8, 2021

I made an attempt at formatting the initial comment into the 'backport' format.

@stephentoub will you look into the servicing considerations?

@adamsitnik adamsitnik added the Servicing-consider Issue for next servicing release review label Oct 8, 2021
@adamsitnik
Copy link
Member

@jeffhandley this PR is ready for being considered for merging to 6.0

@jeffhandley jeffhandley changed the title [release/6.0] SafeFileHandle.Unix: don't DeleteOnClose when lock is not succesful. [release/6.0] SafeFileHandle.Unix: don't DeleteOnClose when lock is not successful. Oct 8, 2021
@danmoseley
Copy link
Member

This also swaps the order of unlink and LOCK_UN in Dispose as it was prior to #55153.
Either order should be fine.

What is the motivation for porting this part? Would it be lower risk to just port the fix itself?

@tmds
Copy link
Member Author

tmds commented Oct 8, 2021

What is the motivation for porting this part? Would it be lower risk to just port the fix itself?

The unlink and flock use distinct variables and both ignore errors. I see no additional risk by swapping them.
I don't think it is absolutely mandatory for the fix. The order is now the same as what it was for previous versions of .NET.
It's also the order we have on main since 3 days (#55327).

@danmoseley
Copy link
Member

It's also the order we have on main since 3 days (#55327).

thanks @tmds. that in particular is a good argument.

@jeffhandley jeffhandley added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Oct 8, 2021
@jeffhandley
Copy link
Member

Approved by tactics. Some of the failing checks were in the IO area; rerunning...

@jeffhandley
Copy link
Member

The System.Tests.TimeZoneInfoTests.TestWindowsNlsDisplayNames failure in runtime (Libraries Test Run release coreclr windows x86 Debug) is #60119, which was fixed in #60140.

@danmoseley
Copy link
Member

WASM failures are tracked by #51961 (comment)
Windows 7 network tests that timed out - I'll open an issue.

@jeffhandley let me know if you'd like me to use my super merging powers

@danmoseley
Copy link
Member

#60204

@danmoseley
Copy link
Member

I'm going to be bold and merge...

@danmoseley danmoseley merged commit eb89bde into dotnet:release/6.0 Oct 8, 2021
@jeffhandley
Copy link
Member

Thanks for merging, @danmoseley. And thanks for the fix, @tmds!

@ghost ghost locked as resolved and limited conversation to collaborators Nov 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.IO community-contribution Indicates that the PR has been added by a community member Servicing-approved Approved for servicing release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants