Closed sterchelen closed 5 years ago
What is the actual exception type and message?
Type -> NullReferenceException Message -> Object reference not set to an instance of an object Stacktrace ->
at Microsoft.AspNetCore.Owin.OwinEnvironment.<>c.<.ctor>b__2_50(IHttpConnectionFeature feature)
at Microsoft.AspNetCore.Owin.OwinEnvironment.FeatureMap`1.<>c__DisplayClass2_0.<.ctor>b__0(Object feature)
at Microsoft.AspNetCore.Owin.OwinEnvironment.FeatureMap.TryGet(HttpContext context, Object& value)
at Microsoft.AspNetCore.Owin.OwinEnvironment.System.Collections.Generic.IDictionary<System.String,System.Object>.TryGetValue(String key, Object& value)
at Nancy.Owin.NancyMiddleware.Get[T](IDictionary`2 env, String key)
at Nancy.Owin.NancyMiddleware.<>c__DisplayClass2_1.<<UseNancy>b__1>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Microsoft.AspNetCore.Owin.WebSocketAcceptAdapter.<>c__DisplayClass6_0.<<AdaptWebSockets>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Command to test :
curl -v --no-buffer -XGET --unix-socket /tmp/sock-test.sock http://localhost/
https://github.com/aspnet/HttpAbstractions/blob/816516f193afcb7ce6b564facc2a36d7e86604ea/src/Microsoft.AspNetCore.Owin/OwinEnvironment.cs#L75-L86 Hmm, it assumes IPs and ports are always available.
Workaround: set those fields to dummy values in a middleware prior to your owin components.
Hmm, it assumes IPs and ports are always available.
Yes, looks like the Nancy middleware pulls server.RemoteIpAddress
for all requests. This should probably be more resilient.
Not sure if there's anything to do in the OWIN adapter? I guess there could be better error handling there as well, or provide dummy/null
values out of the box.
The adapter could return null rather than throwing.
Ah, well, Nancy actually uses TryGetValue
and falls back to default(T)
if the key doesn't exist, so it should handle missing values.
I guess the fix here is to make sure the adapter doesn't throw.
In fact ! Setting IPaddresses to dummy values resolve my issue :
context.Connection.LocalIpAddress = new IPAddress(new byte[] {0, 0, 0, 0});
context.Connection.RemoteIpAddress = new IPAddress(new byte[] {0, 0, 0, 0});
Thank you.
Sounds like there are sufficient workarounds for this scenario. Closing.
Hi,
I'm trying to use unix socket with Owin and Nancy activated. With the
ListenUnixSocket()
all of my requests return500
whereas with the standard tcp biddingListen()
everything is fine ! Here is the stack trace, thanks toUseDeveloperExceptionPage()
:My code that bind the unix socket :
Any ideas ?
Dotnet and owin version --> 2.0.2 Nancy --> 2.0.0
Thanks.