Bug 42518 - HttpListener doesn't close connections (sockets) after HttpListener.Close method
Summary: HttpListener doesn't close connections (sockets) after HttpListener.Close method
Status: RESOLVED NORESPONSE
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 4.2.0 (C6)
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Future Release
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-07-13 13:36 UTC by Raman Sidarakin
Modified: 2018-03-13 11:07 UTC (History)
3 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 on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NORESPONSE

Description Raman Sidarakin 2016-07-13 13:36:26 UTC
HttpListener has Close method, that shutdowns it. 
So, the situation I met:
Client connects to server, that uses HttpListener.
Client sends any request and we call Close method at the HttpListener instance.

Here are little pseudo-code examples.
Server:
HttpListener httpListener = new HttpListener();
httpListener.Prefixes.Add("http://localhost:53000/");
httpListener.Start();
			
HttpListenerContext context = null;
var sync = new object ();
lock (sync) 
{
    httpListener.BeginGetContext (ar => {
        context = httpListener.EndGetContext (ar);
        lock (sync) {
            Monitor.Pulse (sync);
        }		
    }, null);
    Monitor.Wait(sync);
}
httpListener.Close();

Client:
HttpWebRequest request = HttpWebRequest.CreateHttp("http://localhost:53000/");
request.Method = "GET";
var response = request.GetResponse();
Console.WriteLine("Status code: {0}",((HttpWebResponse)response).StatusCode);

In such case, client will get "Status code OK" under mono 4.2.1 and client will get WebException with status "Receive Failure".
So, looks like mono has wrong behavior in such situations.
Comment 1 Rodrigo Kumpera 2016-07-20 19:08:17 UTC
Hi Raman,

Have you tried this with the latest version of mono, 4.4.0?

Could you provide a complete test program that shows the issue?
Comment 2 Marek Safar 2018-03-13 11:07:19 UTC
We have not received the requested information. If you are still experiencing this issue please provide all the requested information and reopen the bug report.

Thank you!