Nancy application error being swallowed by OWIN?

3

I have a Nancy app which i've recently updated to use OWIN/Katana.

For some reason, my "real" errors are now being hidden.

This is the only generic error i receive:

A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread.

Caused By: HttpException·The remote host closed the connection. The error code is 0x800704CD. :0System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect) :0System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush() :0System.Web.HttpResponse.Flush(Boolean finalFlush, Boolean async) :0Microsoft.Owin.Host.SystemWeb.CallStreams.OutputStream.Flush()
:0System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
:0System.IO.StreamWriter.Dispose(Boolean disposing)
:0System.IO.StreamWriter.Close()
:0Newtonsoft.Json.JsonWriter.System.IDisposable.Dispose()
:0Nancy.Serialization.JsonNet.JsonNetSerializer.Serialize(String contentType, TModel model, Stream outputStream)
:0Nancy.Owin.NancyMiddleware+<>c__DisplayClasse.b__a(NancyContext context)
:0System.Threading.Tasks.Task.Execute()

That's not the real error. For some reason my real error isn't being logged anymore after i updated to use OWIN.

My OWIN startup has nothing but app.UseNancy() (no other middleware).

Here's my error handler in ApplicationStartup:

pipelines.OnError.AddItemToEndOfPipeline((context, exception) => OnError(container.Resolve<ILoggingService>(), context, exception));


private static Response OnError(ILoggingService loggingService, NancyContext context, Exception exception)
{
   // log something
}

What am i doing wrong? Do i have to write custom middleware to handle the errors now?

EDIT

An update on this. When it happens, it actually crashes my site/app pool. I'm on .NET 4.5.

.net
.net-4.5
owin
nancy
asked on Stack Overflow Feb 2, 2016 by RPM1984 • edited Jun 20, 2020 by Community

1 Answer

0

Turns out this wasn't Nancy/OWIN directly.

A library i was using (BugSnag) was causing issues. Doesn't seem it supports OWIN properly. So i removed that library and the problem stopped.

answered on Stack Overflow Feb 11, 2016 by RPM1984

User contributions licensed under CC BY-SA 3.0