dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.2k stars 4.72k forks source link

NullReferenceException when setting TcpClient.SendTimeout #23443

Closed fitzchak closed 4 years ago

fitzchak commented 7 years ago

We use netstandard2.0.

See: http://issues.hibernatingrhinos.com/issue/RavenDB-8440

System.NullReferenceException occurred HResult=0x80004003 Message=Object reference not set to an instance of an object. Source= StackTrace: at System.Net.Sockets.TcpClient.set_SendTimeout(Int32 value)

image

image

stephentoub commented 7 years ago

TcpClient._clientSocket is null. How was this TcpClient instance created? Is some code somewhere setting client.Client = null;? Is this code running after the TcpClient has been disposed?

ayende commented 7 years ago

This was created a few lines above this code, and there wasn't anything that would dispose it or should set it to null. We have moved the code to be a bit closer and we'll check this again, I suspect that it is some rare loop causing us to access this after the dispose, though.

If that is the case, can this throw ObjectDisposedException ?

wfurt commented 6 years ago

I was not able to reproduce it @fitzchak. To the questions asked: "Client" is null, "client" is not and that seems to be confusing. Client is property of TcpClient and it should be instantiated to Socket when TcpClient is created. Since this is very old issue, I'm proposing to close it unless you can provide steps to reproduce.