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

Socket: delete unix local endpoint filename on Close #52103

Merged
merged 13 commits into from
May 31, 2021

Conversation

tmds
Copy link
Member

@tmds tmds commented Apr 30, 2021

@ghost
Copy link

ghost commented Apr 30, 2021

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

Issue Details

Fixes #45537

@antonfirsov @geoffkizer ptal

Author: tmds
Assignees: -
Labels:

area-System.Net.Sockets

Milestone: -

@tmds
Copy link
Member Author

tmds commented Apr 30, 2021

I just realized relative paths need specific handling. The working directory may change between the time of Bind and Dispose. I'll update the PR for this, no need to review it yet.

@wfurt
Copy link
Member

wfurt commented Apr 30, 2021

should the file be deleted only if created by .NET ? ... or is it always the case e.g. the local endpoint is transient?

@antonfirsov

This comment has been minimized.

@azure-pipelines

This comment has been minimized.

@tmds
Copy link
Member Author

tmds commented May 3, 2021

should the file be deleted only if created by .NET ? ... or is it always the case e.g. the local endpoint is transient?

The file is created when the socket is bound. If the file is already there, the socket will fail to bind.

// correct type (IPEndPoint, etc). The Bind operation sets _rightEndPoint. Other operations must only set
// it when the value is still null.
// This enables tracking the file created by UnixDomainSocketEndPoint when the Socket is bound,
// and to delete that file when the Socket gets disposed.
Copy link
Member Author

Choose a reason for hiding this comment

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

I avoided adding a field to Socket for the stake of tracking the file to be deleted. Instead this is tracked through _rightEndPoint UnixDomainSocketEndPoint.BoundFileName.
On Bind an instance is created that has this property set. And on dispose, the file then gets deleted.

Copy link
Member

Choose a reason for hiding this comment

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

I've wondered this for a while... what does the "right" part of the name mean?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just guessing: right type. The name is not very clear. Maybe we should change it to _typedEndpoint or _endpointType?

Copy link
Member

Choose a reason for hiding this comment

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

I keep asking this question every time I see that variable.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really know either. Would love to understand.

It might be "right" in the sense that it's the result after resolving wildcards like port=0. Does that seem right?

@tmds
Copy link
Member Author

tmds commented May 11, 2021

@antonfirsov @geoffkizer can you continue reviewing this?

@antonfirsov
Copy link
Member

@tmds the UnixDomainSocketEndPoint changes look good to me. I'm only concerned about caching optimizations (discussion above).

@karelz
Copy link
Member

karelz commented May 18, 2021

Triage: @tmds can you please remove endpoint optimization from this change? We can make it separate PR and discuss there if and how we want it to behave.

@tmds
Copy link
Member Author

tmds commented May 18, 2021

I need to look at the CI failures, they seem related to the change.

Triage: @tmds can you please remove endpoint optimization from this change? We can make it separate PR and discuss there if and how we want it to behave.

The discussion is more about #39313 than it is about this PR. Can we remove the optimization if it is decided to revert that PR? It will then happen as part of removing the _localEndPoint field that was introduced in #39313. @antonfirsov wdyt?

@antonfirsov
Copy link
Member

@tmds we are undecided yet re reverting _localEndpoint I plan to open a separate issue to continue discussions on that topic. The point is that in this PR it is better to push this concern out of scope and revert the changes dealing with _localEndpoint, so this question does not block us to go ahead and merge the UDS improvement.

I need to look at the CI failures, they seem related to the change.

I can't see the failures, I assume it was outerloop which disappeared from the log, will rerun those tests.

@antonfirsov
Copy link
Member

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@tmds
Copy link
Member Author

tmds commented May 19, 2021

The point is that in this PR it is better to push this concern out of scope and revert the changes dealing with _localEndpoint, so this question does not block us to go ahead and merge the UDS improvement.

The concern isn't about how this PR uses _localEndpoint but whether there should be a _localEndpoint. I don't see why I shouldn't use it while it is here, but I'll remove it based on your feedback.

@@ -284,7 +287,7 @@ public int Available
{
// Update the state if we've become connected after a non-blocking connect.
_isConnected = true;
_rightEndPoint = _nonBlockingConnectRightEndPoint;
_rightEndPoint ??= _nonBlockingConnectRightEndPoint;
Copy link
Member

Choose a reason for hiding this comment

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

In what situation will it be non-null? I'm wondering in what situation we previously would have overwritten it and now we won't...

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't think about this much. I replaced everything with a conditional assignment except for the one in Bind.

It can be non-null if for example you Bind first, and then do a Connect and then call LocalEndPoint and end up in this branch.
We don't want to overwrite it because that will lose the tracking (via _rightEndPoint) of the unix socket file we need to delete.

Copy link
Member

@antonfirsov antonfirsov May 25, 2021

Choose a reason for hiding this comment

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

Maybe it would make sense to add a test for this case, so we don't break it in the future. Scratch it would be too difficult because of timing.

Copy link
Member

@antonfirsov antonfirsov left a comment

Choose a reason for hiding this comment

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

@antonfirsov
Copy link
Member

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@antonfirsov antonfirsov left a comment

Choose a reason for hiding this comment

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

LGTM. CI failures are unrelated build failures.

@antonfirsov antonfirsov merged commit d3ed5a9 into dotnet:main May 31, 2021
thaystg added a commit to thaystg/runtime that referenced this pull request Jun 1, 2021
…asm_debugger_and_use_debugger_agent

* upstream/main: (597 commits)
  Fix42292 (dotnet#52463)
  [mono] Remove some obsolete emscripten flags. (dotnet#53486)
  Fixed path to projects (dotnet#53435)
  support ServerCertificateContext in quic (dotnet#53175)
  Socket: delete unix local endpoint filename on Close (dotnet#52103)
  [mono] Fix sgen_gc_info.memory_load_bytes (dotnet#53364)
  Refactor MsQuic's native IP address types. (dotnet#53461)
  Re-enabled optimizations for gtFoldExprConst (dotnet#53347)
  Add diagnostic support into sample app and AppBuilders on Mono. (dotnet#53361)
  Fix issues with virtuals and mdarrays (dotnet#53400)
  Split Variant marshalling tests (dotnet#53035)
  Update clrjit.natvis to cover GT_SIMD and GT_HWINTRINSIC (dotnet#53470)
  remove WSL checks in tests (dotnet#53475)
  Always spawn message loop thread for SystemEvents (dotnet#53467)
  add AcceptAsync cancellation overloads (dotnet#53340)
  Remove unnecessary reference to iOS workload pack in the Mono workload (dotnet#53425)
  Add CookieContainer.GetAllCookies (dotnet#53441)
  Remove DynamicallyAccessedMembers on JsonSerializer  (dotnet#53235)
  [wasm] Re-enable Wasm.Build.Tests (dotnet#53433)
  [libraries] Move library tests Feature Switches defaults to Functional tests (dotnet#53253)
  ...
@ghost ghost locked as resolved and limited conversation to collaborators Jun 30, 2021
@karelz karelz added this to the 6.0.0 milestone Jul 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

proposal: delete unix socket path on Dispose of bound Socket
6 participants