Bug 42518 - HttpListener doesn't close connections (sockets) after HttpListener.Close method
Summary: HttpListener doesn't close connections (sockets) after HttpListener.Close method
Status: NEEDINFO
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: 2016-07-20 19:08 UTC (History)
3 users (show)

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


Attachments

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?

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