Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET 5 RC1 breaks with "Address family not supported by protocol" in AWS Lambda but not in preview 8 and earlier #42233

Closed
normj opened this issue Sep 15, 2020 · 12 comments

Comments

@normj
Copy link

normj commented Sep 15, 2020

Description

I apologize for not having all of the data yet but given the closeness to the GA release I wanted to get the conversation started as soon as possible. I'll add more information as I continue my research.

AWS Lambda, which is the serverless offering at AWS, allows users to deploy Lambda functions as a self contained publish bundle for .NET developers. It has been possible to use .NET 5 preview versions in Lambda up till the latest RC1. Now when users deploy their functions it fails right away access the Lambda API through the HttpClient with the following error messages.

Unhandled exception. System.Net.Http.HttpRequestException: Address family not supported by protocol (127.0.0.1:9001)
 ---> System.Net.Sockets.SocketException (97): Address family not supported by protocol
   at System.Net.Sockets.Socket..ctor(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
   at System.Net.Connections.SocketsConnectionFactory.CreateSocket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType, EndPoint endPoint, IConnectionProperties options)
   at System.Net.Connections.SocketsConnectionFactory.ConnectAsync(EndPoint endPoint, IConnectionProperties options, CancellationToken cancellationToken)
   at System.Net.Http.ConnectHelper.ConnectAsync(ConnectionFactory factory, DnsEndPoint endPoint, IConnectionProperties options, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.ConnectHelper.ConnectAsync(ConnectionFactory factory, DnsEndPoint endPoint, IConnectionProperties options, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken)
   at Amazon.Lambda.RuntimeSupport.InternalRuntimeApiClient.NextAsync(CancellationToken cancellationToken)
   at Amazon.Lambda.RuntimeSupport.RuntimeApiClient.GetNextInvocationAsync(CancellationToken cancellationToken)
   at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.InvokeOnceAsync(CancellationToken cancellationToken)
   at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.RunAsync(CancellationToken cancellationToken)
   at Lambda5Test.Function.Main(String[] args) in C:\Temp\Lambda5Test\src\Lambda5Test\Function.cs:line 21
   at Lambda5Test.Function.<Main>(String[] args)

The address it is connecting to is Lambda's runtime API what all functions have to interact with.

My theory is the HttpClient is attempting to use IPv6 which Lambda does not support and the recent changes to the SocketsConnectionFactory are triggering HttpClient to use IPv6. In particular the following constructor that is defaulting the AddressFamily enum value for IPv6

: this(AddressFamily.InterNetworkV6, socketType, protocolType)

Configuration

Running in AWS under Amazon Linux 2 in the Lambda environment with no IPv6 support.

Regression?

This has worked up through .NET 5 Preview 8.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Sep 15, 2020
@Dotnet-GitSync-Bot
Copy link
Collaborator

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost
Copy link

ghost commented Sep 15, 2020

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@geoffkizer
Copy link
Contributor

Pretty sure this is fixed in RC2 by #42075. Can you grab an RC2 build and confirm?

@ghost
Copy link

ghost commented Sep 15, 2020

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@normj
Copy link
Author

normj commented Sep 15, 2020

That is great if already fixed. I have tried to with the nightly builds of RC2 but since I have to do a self-contained published I get the following errors:

... publish: /home/ec2-user/NET5LambdaTest/src/NET5LambdaTest/NET5LambdaTest.csproj : error NU1102: Unable to find package Microsoft.NETCore.App.Runtime.linux-x64 with version (= 5.0.0-rc.2.20462.5)
... publish: /home/ec2-user/NET5LambdaTest/src/NET5LambdaTest/NET5LambdaTest.csproj : error NU1102:   - Found 29 version(s) in nuget.org [ Nearest version: 5.0.0-rc.1.20451.14 ]
... publish: /home/ec2-user/NET5LambdaTest/src/NET5LambdaTest/NET5LambdaTest.csproj : error NU1102: Unable to find package Microsoft.AspNetCore.App.Runtime.linux-x64 with version (= 5.0.0-rc.2.20464.16)
... publish: /home/ec2-user/NET5LambdaTest/src/NET5LambdaTest/NET5LambdaTest.csproj : error NU1102:   - Found 31 version(s) in nuget.org [ Nearest version: 5.0.0-rc.1.20451.17 ]

Any suggestions on how to do self contained publishes using a nightly build?

@richlander
Copy link
Member

@normj
Copy link
Author

normj commented Sep 15, 2020

Whoops, should a look a little harder and I would have seen the nuget.config.

The good news is I did confirmed with rc.2.20464.14 the issue is fixed and I was successfully able to run a self contained .NET 5 RC2 Lambda function. Thanks for getting back with me so quickly, just had a bit of freak out of .NET 5 going out with a breaking issue for us 😅

@danmoseley
Copy link
Member

danmoseley commented Sep 15, 2020

@geoffkizer just curious I thought #42075 added new api and a code change would have been required to be affected by that change?

@normj i guess we can close this? Thanks so much for reporting it!

@geoffkizer
Copy link
Contributor

@danmosemsft Yeah, it's a little complicated...

This bug was introduced when we did the original System.Net.Connections work in #39524. That was mostly reverted in #41648, but we kept some of the changes from #39524 to try to minimize code churn. Unfortunately, that included this bug.

When reviewing #42075, @stephentoub noticed the issue here and so we fixed it as part of that PR -- meaning we reverted back to the original pre-#39524 behavior.

I wish we had a test for this, but it would require an environment where IPv6 is not supported. Ideally, we'd add that to CI but it's probably far from trivial.

@Gnbrkm41
Copy link
Contributor

Run the test in a docker container with --sysctl net.ipv6.conf.all.disable_ipv6=1? 😄

@normj
Copy link
Author

normj commented Sep 15, 2020

@danmosemsft yes I'm good closing this now that it has been confirmed to be fixed in RC2.

@normj normj closed this as completed Sep 15, 2020
@danmoseley
Copy link
Member

@geoffkizer ah..

@karelz karelz added this to the 5.0.0 milestone Sep 15, 2020
@karelz karelz added bug and removed untriaged New issue has not been triaged by the area owner labels Sep 15, 2020
martincostello added a commit to martincostello/alexa-london-travel that referenced this issue Sep 16, 2020
Update to a prerelease version of .NET 5 RC2 to resolve the main branch being broken due to dotnet/runtime#42233.
@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
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

8 participants