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

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


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();
// ...
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
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.

Note You need to log in before you can comment on or make changes to this bug.