Skip to content

Conversation

@wfurt
Copy link
Member

@wfurt wfurt commented May 19, 2022

fixes #69493
Socket can be explicitly set to null after created in constructor.

@wfurt wfurt requested a review from a team May 19, 2022 04:12
@wfurt wfurt self-assigned this May 19, 2022
@ghost
Copy link

ghost commented May 19, 2022

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

Issue Details

fixes #69493
Socket can be explicitly set to null after created in constructor.

Author: wfurt
Assignees: wfurt
Labels:

area-System.Net.Sockets

Milestone: -

@wfurt
Copy link
Member Author

wfurt commented May 19, 2022

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@MihaZupan
Copy link
Member

MihaZupan commented May 19, 2022

It looks like all Connect(Async) overloads suffer from the same issue. The test was just only doing this for one of the overloads.
For some reason, only one of the overloads supported this before your change?

@wfurt
Copy link
Member Author

wfurt commented May 19, 2022

It looks like all Connect(Async) overloads suffer from the same issue. The test was just only doing this for one of the overloads.
For some reason, only one of the overloads supported this before your change?

yes, it seems like.
I guess in most use cases people don't expect Connect to work after the Socket is explicitly removed. I think this would be easy to fix as well.

@wfurt
Copy link
Member Author

wfurt commented May 19, 2022

I made another change @MihaZupan to set the Socket as needed if user pass in null. This would get us to same state as we would be in initially e.g. mimics the constructor behavior. That is some behavior change but it feels better than guarding every single Connect overload.
That broke ExclusiveAddressUse_NullClient test as now we will get OS/Socket default instead of always false.
Since the property defers to underlying Socket I see no value in the test to enforce false in this case.

@MihaZupan
Copy link
Member

Technically this makes it so you can never observe TcpClient.Client being null, even after you set it.
But that's probably a good thing - I don't see any value in carrying around an empty TcpClient.

@MihaZupan
Copy link
Member

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@wfurt
Copy link
Member Author

wfurt commented May 20, 2022

all failures are unrelated

@wfurt wfurt merged commit c94b2f7 into dotnet:main May 20, 2022
@wfurt wfurt deleted the TCPClient branch May 20, 2022 01:05
@ghost ghost locked as resolved and limited conversation to collaborators Jun 19, 2022
@karelz karelz added this to the 7.0.0 milestone Jul 19, 2022
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.

TcpClient.Connect throws NRE if the Socket is cleared

4 participants