Bug 12012 - TcpClient.Close() doesn't work
Summary: TcpClient.Close() doesn't work
Status: NEEDINFO
Alias: None
Product: Runtime
Classification: Mono
Component: General (show other bugs)
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-04-28 15:55 UTC by Gintas
Modified: 2018-01-18 21:28 UTC (History)
6 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 12012 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEEDINFO

Description Gintas 2013-04-28 15:55:44 UTC
It works perfectly fine(server notices when client disconnects) when launching it without Mono on Windows. When using Mono on Windows or Linux it just doesn't work, server doesn't notice that client disconnected.

TcpClient socket = new TcpClient();
NetworkStream stream = socket.GetStream();
// ...
stream.Close();
socket.Close();
Comment 1 Ashley 2013-09-20 20:24:35 UTC
I've observed that TcpClient also doesn't seem to notice when the server closes the connection from its end. Attempting to read or write from it eventually causes a timeout, but does not change the connected state or indicate that the connection has been lost.
Comment 2 leonardo.taglialegne 2014-09-15 04:40:16 UTC
I could reproduce this on mono 3.10.
If the server sends an RST the client doesn't notice that the connection is closed, and timeouts without setting Connected to false.
Comment 3 pr0vieh 2014-12-31 07:54:37 UTC
Confirmed!
it makes for a very bad network performance of mono
we need network performance!
I hope someone is looking at this soon
this bug is exist long enough...
Comment 4 Ludovic Henry 2018-01-18 21:28:27 UTC
Have you tried setting the `socket.LingerState` parameter? The behavior when calling `socket.Close()` is to simply call `close` on the socket and leave the OS deal with lingering. 

If you can still reproduce with latest version of Mono, please attach the output for a run with `MONO_LOG_MASK=io-layer` and `MONO_LOG_LEVEL=debug` environment variables defined. This should give us some information about the different calls that happens on the socket.

Thank you.