Hello.
EmbedIO.WebServer with _HttpListenerMode=Microsoft_ crushes on Linux after any HTTP request with exception:
System.ObjectDisposedException:
Cannot access a disposed object.
Object name: 'System.Net.HttpListenerResponse'.
But in Windows it working as intended.
With _HttpListenerMode=EmbedIO_ in Linux it works too.
Affected enviroment
Steps to reproduce
Minimal example:
using EmbedIO;
using EmbedIO.Actions;
using System;
namespace Test1
{
class Program
{
static void Main(string[] args)
{
new WebServer(o => o.WithUrlPrefix("http://localhost:3000").WithMode(HttpListenerMode.Microsoft))
.WithModule(new ActionModule("/", HttpVerbs.Any, ctx => ctx.SendDataAsync(new { Message = "Hello world!" })))
.Start();
Console.ReadKey();
}
}
}
Exception details from console
01:07:00.246 ERR >> [WebServer] [Vde65z5I60uOVpmTH7e+3Q] Fatal exception.
$type : System.ObjectDisposedException
Message :
Cannot access a disposed object.
Object name: 'System.Net.HttpListenerResponse'.
ObjectName : System.Net.HttpListenerResponse
TargetSite : Void CheckDisposed()
StackTrace :
at System.Net.HttpListenerResponse.CheckDisposed()
at System.Net.HttpListenerResponse.get_OutputStream()
at EmbedIO.Net.Internal.SystemHttpResponse.get_OutputStream()
at EmbedIO.WebServerBase`1.DoHandleContextAsync(IHttpContextImpl context)
Source : System.Net.HttpListener
HResult : -2146232798
Hello @NoTimeForHero, thanks for using EmbedIO!
Thank you also for the gazillionth reason why ditching HttpListener would make EmbedIO a better library.
Unfortunately, digging into .NET Core's runtime source code to try and debug this issue would not only cost hours of time, not to mention headache medication(*) — it would be pointless, since HttpListener has long been deemed obsolete and unworthy of any serious maintenance.
All the advice I can give is to steer away from the configuration that is giving you trouble: use HttpListenerMode.EmbedIO.
(*) no overstatement here: been there, done that — more than once.
Hi. I'm having the same issue while using HttpListernerMode.EmbedIO
My full error log (incase curious) https://pastebin.com/5D0m4v7g
I've updated it to HttpListenerMode.Microsoft for testing purposes, seeing if this resolves the issue for me. Prior to this I was using mode EmbedIO
private static WebServer CreateWebServer(string u)
{
var server = new WebServer(o => o
.WithUrlPrefix(u)
.WithMode(HttpListenerMode.Microsoft))
.WithCors()
// First, we will configure our web server by adding Modules.
.WithLocalSessionManager()
.WithWebApi("/api", m => m.RegisterController(() => new ApiController()));
// Listen for state changes.
server.StateChanged += (s, e) => Logging.Log($"WebServer New State - {e.NewState}");
return server;
}
Update: HttpListenerMode.Microsoft is even worse. Doesn't work at all lol. Back to HttpListenerMode.EmbedIO - Still the same issue Cannot access a disposed object.
My ApiManager.cs:
public ApiManager(string url)
{
this.url = url;
}
public void startServer()
{
Thread t = new Thread(() =>
{
Logging.Log("Starting web api server..");
using (var server = CreateWebServer(url))
{
server.RunAsync();
Logging.Log("Started web api server.");
Thread.Sleep(-1);
}
});
t.Start();
this.serverThread = t;
}
private static WebServer CreateWebServer(string u)
{
var server = new WebServer(o => o
.WithUrlPrefix(u)
.WithMode(HttpListenerMode.Microsoft))
.WithCors()
// First, we will configure our web server by adding Modules.
.WithLocalSessionManager()
.WithWebApi("/api", m => m.RegisterController(() => new ApiController()));
// Listen for state changes.
server.StateChanged += (s, e) => Logging.Log($"WebServer New State - {e.NewState}");
return server;
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.