Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Server fails to start with "error -97 EAFNOSUPPORT address family not supported" #1474

Closed
MarkusAmshove opened this issue Mar 10, 2017 · 14 comments
Assignees

Comments

@MarkusAmshove
Copy link

MarkusAmshove commented Mar 10, 2017

Hello,

I'm using the ASP.NET Core project template from Visual Studio 2017 and built it with docker, pushed it to the registry and then pulled it on my QNAP NAS.

When trying to start the container I get the following stacktrace:

crit: Microsoft.AspNetCore.Server.Kestrel[0]                                                                                                                                                                                                                                                                                                                                             
      Unable to start Kestrel.                                                                                                                                                                                                                                                                                                                                                           
System.AggregateException: One or more errors occurred. (Error -97 EAFNOSUPPORT address family not supported) ---> Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException: Error -97 EAFNOSUPPORT address family not supported                                                                                                                                              
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv.tcp_bind(UvTcpHandle handle, SockAddr& addr, Int32 flags)                                                                                                                                                                                                                                                            
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle.Bind(ServerAddress address)                                                                                                                                                                                                                                                                                    
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListenerPrimary.CreateListenSocket()                                                                                                                                                                                                                                                                                          
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener.<StartAsync>b__8_0(Object state)                                                                                                                                                                                                                                                                                        
--- End of stack trace from previous location where exception was thrown ---                                                                                                                                                                                                                                                                                                             
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()                                                                                                                                                                                                                                                                                                                     
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)                                                                                                                                                                                                                                                                                     
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()                                                                                                                                                                                                                                                                                          
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary.<StartAsync>d__12.MoveNext()                                                                                                                                                                                                                                                                                     
   --- End of inner exception stack trace ---                                                                                                                                                                                                                                                                                                                                            
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)                                                                                                                                                                                                                                                                                              
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)                                                                                                                                                                                                                                                                                   
   at System.Threading.Tasks.Task.Wait()                                                                                                                                                                                                                                                                                                                                                 
   at Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelEngine.CreateServer(ServerAddress address)                                                                                                                                                                                                                                                                                     
   at Microsoft.AspNetCore.Server.Kestrel.KestrelServer.Start[TContext](IHttpApplication`1 application)                                                                                                                                                                                                                                                                                  
---> (Inner Exception #0) Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException: Error -97 EAFNOSUPPORT address family not supported                                                                                                                                                                                                                                       
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv.tcp_bind(UvTcpHandle handle, SockAddr& addr, Int32 flags)                                                                                                                                                                                                                                                            
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle.Bind(ServerAddress address)                                                                                                                                                                                                                                                                                    
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListenerPrimary.CreateListenSocket()                                                                                                                                                                                                                                                                                          
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener.<StartAsync>b__8_0(Object state)                                                                                                                                                                                                                                                                                        
--- End of stack trace from previous location where exception was thrown ---                                                                                                                                                                                                                                                                                                             
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()                                                                                                                                                                                                                                                                                                                     
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)                                                                                                                                                                                                                                                                                     
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()                                                                                                                                                                                                                                                                                          
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary.<StartAsync>d__12.MoveNext()<---                                                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                                                                                                                                         
Unhandled Exception: System.AggregateException: One or more errors occurred. (Error -97 EAFNOSUPPORT address family not supported) ---> Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException: Error -97 EAFNOSUPPORT address family not supported                                                                                                                         
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv.tcp_bind(UvTcpHandle handle, SockAddr& addr, Int32 flags)                                                                                                                                                                                                                                                            
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle.Bind(ServerAddress address)                                                                                                                                                                                                                                                                                    
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListenerPrimary.CreateListenSocket()                                                                                                                                                                                                                                                                                          
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener.<StartAsync>b__8_0(Object state)                                                                                                                                                                                                                                                                                        
--- End of stack trace from previous location where exception was thrown ---                                                                                                                                                                                                                                                                                                             
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()                                                                                                                                                                                                                                                                                                                     
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)                                                                                                                                                                                                                                                                                     
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()                                                                                                                                                                                                                                                                                          
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary.<StartAsync>d__12.MoveNext()                                                                                                                                                                                                                                                                                     
   --- End of inner exception stack trace ---                                                                                                                                                                                                                                                                                                                                            
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)                                                                                                                                                                                                                                                                                              
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)                                                                                                                                                                                                                                                                                   
   at System.Threading.Tasks.Task.Wait()                                                                                                                                                                                                                                                                                                                                                 
   at Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelEngine.CreateServer(ServerAddress address)                                                                                                                                                                                                                                                                                     
   at Microsoft.AspNetCore.Server.Kestrel.KestrelServer.Start[TContext](IHttpApplication`1 application)                                                                                                                                                                                                                                                                                  
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.Start()                                                                                                                                                                                                                                                                                                                              
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host, CancellationToken token, String shutdownMessage)                                                                                                                                                                                                                                                                 
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host)                                                                                                                                                                                                                                                                                                                  
   at MusikGeschaeft.Program.Main(String[] args) in D:\scm\MusikGeschaeft\MusikGeschaeft\Program.cs:line 23

I did not change anything on the project itself, so it's just built as is (from the template).

I've tried all 3 network modes (Bridge, NAT, Host) but I always get the same error.

Searching for the error just points me to issues which were closed without any hint on what goes wrong .

The image is hosted at dockerhub:
https://hub.docker.com/r/markusamshove/musikgeschaeft/

@halter73
Copy link
Member

I tried out your image on Debian 8.2 and don't see the EAFNOSUPPORT. The results of my experiment can be seen in this gist.

Have you tried changing your binding from http://*:80 to http://0.0.0.0:80? That seems to have fixed the problem for the reporter of #766.

@MarkusAmshove
Copy link
Author

Thanks, that resolved the problem.

Didn't think about IPV6 :-)

Thank you!

@halter73
Copy link
Member

Reopenning for triaging. I think we could do what I suggested in this comment, and try binding to 0.0.0.0 automatically if binding to :: fails when someone tries to bind to "http://*". Either that or log an easier-to-understand error.

If we remove or change IServerAddressesFeature it might no longer be necessary to change this since the binding endpoint would be more explicit.

@halter73 halter73 reopened this Mar 14, 2017
@MarkusAmshove
Copy link
Author

Is http://* the default binding?

I used the default option (not using BaseUrls explicitly) and when the error occured I tried http://*:80, which still tried to bind to IPv6.

@halter73
Copy link
Member

The default binding is normally http://localhost:5000, but our default docker image changes it to http://+:80 (which is equivalent to http://*) via the ASPNETCORE_URLS environment variable.

We currently handle not being able to bind to ::1 by simply binding just to 127.0.0.1 and logging a warning when "localhost" is specified. It's logical that we could do something similar for :: and 0.0.0.0 when "*" is specified.

Previously we weren't able to reproduce the EAFNOSUPPORT issue though. @MarkusAmshove can you provide us with the exact host and guest distro versions you were using when you ran into this issue?

@MarkusAmshove
Copy link
Author

I'm using a QNAP TS-251+ (it's a NAS).

Host

$ uname -a
Linux server 3.12.6 #1 SMP Mon Mar 13 01:11:46 CST 2017 x86_64 unknown
$ cat /proc/version
Linux version 3.12.6 (root@NasX86-12) (gcc version 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)) #1 SMP Mon Mar 13 01:11:46 CST 2017

It does support IPV6, but I haven't enabled it.

Guest

The guest is using

microsoft/aspnetcore:1.1

which uses microsoft/dotnet:1.1.1-runtime itself.

Tracking down the Dockerfiles it is debian:jessie at the root.

Windows 10

I can't reproduce it on Windows by simply disabling IPv6:

$ Get-NetAdapter

Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
----                      --------------------                    ------- ------       ----------             ---------
vEthernet (DockerNAT)     Hyper-V Virtual Ethernet Adapter             17 Up           00-15-5D-01-65-07        10 Gbps
Ethernet                  Intel(R) Ethernet Connection (2) I218-V      15 Up           D0-50-99-42-E7-B8         1 Gbps
$ Disable-NetAdapterBinding -InterfaceAlias Ethernet -ComponentID ms_tcpip6
$ docker run markusamshove/musikgeschaeft:latest
Hosting environment: Production
Content root path: /app
Now listening on: http://*:80
Application started. Press Ctrl+C to shut down.

trying to force disable IPv6 by using

docker run --network 7283e142515a --sysctl net.ipv6.conf.all.disable_ipv6=1 -d markusamshove/musikgeschaeft:latest```

also doesn't force the error

----


I can't tell why its not reproducable by simply turning off IPv6, it's a bit strange.

Maybe the custom Ubuntu 4 behaves differently than more "modern" OSes when trying to bind to IPv6 which isn't enabled.

However, I think its a reasonable default setting to try to bind to IPv6 and as a fallback also try to bind to IPv4, as you suggested.

I'm happy to try it out if you want me to :-)

@muratg
Copy link
Contributor

muratg commented Mar 20, 2017

Assigning to @halter73 for investigation.

@muratg muratg assigned natemcmaster and unassigned halter73 Apr 7, 2017
@muratg muratg added this to the 2.0.0 milestone Apr 7, 2017
@natemcmaster natemcmaster changed the title Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException: Error -97 EAFNOSUPPORT address family not supported Server fails to start with "error -97 EAFNOSUPPORT address family not supported" Apr 19, 2017
@zmk523
Copy link

zmk523 commented Feb 7, 2018

I just started having this occur in our Azure App Service a few days back. We're using AspNetCore 2.1.4.

@halter73
Copy link
Member

halter73 commented Feb 7, 2018

@zmk523 Can you show us your logs? The EAFNOSUPPORT binding issue should be benign on azure and should only be logged as a warning. Are you seeing any other problems with your app, or just this log?

@natemcmaster
Copy link
Contributor

Also, can you share which version of ASP.NET Core you are using? This is listed as a PackageReference element in your .csproj file. You said ASP.NET Core 2.1.4, but there is no such thing. I'm guessing the "2.1.4" is the SDK version, but the SDK can be used to build and app with Kestrel 1.0, 1.1, 2.0, etc.

@zmk523
Copy link

zmk523 commented Feb 8, 2018

@natemcmaster
I'm sorry. I was in a hurry. I was wrong. I misunderstood you.
The SDK version is 2.1.4

@zmk523
Copy link

zmk523 commented Feb 8, 2018

@halter73
The logs are as follows:
crit: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to start Kestrel.

Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvException: Error -4092 EACCES permission denied
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions.ThrowError(Int32 statusCode)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions.tcp_bind(UvTcpHandle handle, SockAddr& addr, Int32 flags)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvTcpHandle.Bind(IPEndPoint endPoint)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Listener.ListenTcp(Boolean useFileHandle)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Listener.CreateListenSocket()
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Listener.<>c.b__8_0(Listener listener)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvThread.CallbackAdapter1.<>c.<.cctor>b__3_1(Object callback, Object state) at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvThread.DoPostWork() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ListenerPrimary.<StartAsync>d__15.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.LibuvTransport.<BindAsync>d__20.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.LibuvTransport.<BindAsync>d__20.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.<>c__DisplayClass21_01.<g__OnBind|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.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.EndpointsStrategy.d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.d__21`1.MoveNext()

Unhandled Exception: Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvException: Error -4092 EACCES permission denied
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions.ThrowError(Int32 statusCode)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions.tcp_bind(UvTcpHandle handle, SockAddr& addr, Int32 flags)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvTcpHandle.Bind(IPEndPoint endPoint)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Listener.ListenTcp(Boolean useFileHandle)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Listener.CreateListenSocket()
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Listener.<>c.b__8_0(Listener listener)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvThread.CallbackAdapter1.<>c.<.cctor>b__3_1(Object callback, Object state) at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvThread.DoPostWork() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ListenerPrimary.<StartAsync>d__15.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.LibuvTransport.<BindAsync>d__20.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.LibuvTransport.<BindAsync>d__20.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.<>c__DisplayClass21_01.<g__OnBind|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.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.EndpointsStrategy.d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.d__21`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.d__26.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host)
at XX.Admin.API.Program.Main(String[] args) in ...

@natemcmaster
Copy link
Contributor

EACCES is a different error. This typically means the port you tried to bind to is already in use, or that the port is reserved by the system.

Can you open a separate bug for this? This issue was about EAFNOSUPPORT

@zmk523
Copy link

zmk523 commented Feb 8, 2018

@natemcmaster
I understand the reason for using the encrypted SSL authentication binding to register and use KestrelServer.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants