Skip to content

[.NET 5 RC1] "HttpRequestException: Address family not supported by protocol (127.0.0.1:9001)" thrown when Lambda invoked #730

@martincostello

Description

@martincostello

Description

I have a Lambda function that uses the .NET Core custom runtime via the Amazon.Lambda.RuntimeSupport NuGet package, so with the release of .NET 5.0 RC1 as a "go live" release I updated it to target net5.0 using RC1 to try it out.

The tests passed as expected in CI, however when the Lambda was deployed to the Lambda environment it failed with the exception:

System.Net.Http.HttpRequestException: Address family not supported by protocol (127.0.0.1:9001)

The error comes from the HTTP call made here:

var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);

Reproduction Steps

Clone the Lambda function from martincostello/alexa-london-travel@d5d7618 and deploy to AWS Lambda and invoke the function.

Logs

  | 2020-09-14T23:10:37.855+01:00 | Unhandled exception. System.Net.Http.HttpRequestException: Address family not supported by protocol (127.0.0.1:9001)
  | 2020-09-14T23:10:37.855+01:00 | ---> System.Net.Sockets.SocketException (97): Address family not supported by protocol
  | 2020-09-14T23:10:37.855+01:00 | at System.Net.Sockets.Socket..ctor(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
  | 2020-09-14T23:10:37.855+01:00 | at System.Net.Connections.SocketsConnectionFactory.CreateSocket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType, EndPoint endPoint, IConnectionProperties options)
  | 2020-09-14T23:10:37.855+01:00 | at System.Net.Connections.SocketsConnectionFactory.ConnectAsync(EndPoint endPoint, IConnectionProperties options, CancellationToken cancellationToken)
  | 2020-09-14T23:10:37.855+01:00 | at System.Net.Http.ConnectHelper.ConnectAsync(ConnectionFactory factory, DnsEndPoint endPoint, IConnectionProperties options, CancellationToken cancellationToken)
  | 2020-09-14T23:10:37.855+01:00 | --- End of inner exception stack trace ---
  | 2020-09-14T23:10:37.855+01:00 | at System.Net.Http.ConnectHelper.ConnectAsync(ConnectionFactory factory, DnsEndPoint endPoint, IConnectionProperties options, CancellationToken cancellationToken)
  | 2020-09-14T23:10:37.855+01:00 | at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
  | 2020-09-14T23:10:37.855+01:00 | at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
  | 2020-09-14T23:10:37.855+01:00 | at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
  | 2020-09-14T23:10:37.855+01:00 | at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
  | 2020-09-14T23:10:37.855+01:00 | at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
  | 2020-09-14T23:10:37.855+01:00 | at System.Net.Http.HttpClient.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken)
  | 2020-09-14T23:10:37.855+01:00 | at Amazon.Lambda.RuntimeSupport.InternalRuntimeApiClient.NextAsync(CancellationToken cancellationToken)
  | 2020-09-14T23:10:37.855+01:00 | at Amazon.Lambda.RuntimeSupport.RuntimeApiClient.GetNextInvocationAsync(CancellationToken cancellationToken)
  | 2020-09-14T23:10:37.855+01:00 | at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.InvokeOnceAsync(CancellationToken cancellationToken)
  | 2020-09-14T23:10:37.855+01:00 | at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.RunAsync(CancellationToken cancellationToken)
  | 2020-09-14T23:10:37.855+01:00 | at MartinCostello.LondonTravel.Skill.FunctionEntrypoint.RunAsync(HttpClient httpClient, CancellationToken cancellationToken) in /_/src/LondonTravel.Skill/FunctionEntrypoint.cs:line 42
  | 2020-09-14T23:10:37.855+01:00 | at MartinCostello.LondonTravel.Skill.FunctionEntrypoint.Main() in /_/src/LondonTravel.Skill/FunctionEntrypoint.cs:line 52
  | 2020-09-14T23:10:37.855+01:00 | at MartinCostello.LondonTravel.Skill.FunctionEntrypoint.<Main>()
  | 2020-09-14T23:10:37.939+01:00 | START RequestId: e9f44aa6-1849-46e8-9fd7-60b2cb95620b Version: $LATEST

While not yet supported by AWS Lambda itself, I thought I'd raise this here in the first instance in case this is an issue that stems from the Lambda runtime. If it is not, then I can open the issue against the dotnet/runtime repo for investigation.

Environment

  • Build Version: 1.1.1
  • OS Info: AmazonLinux
  • Build Environment: dotnet SDK
  • Targeted .NET Platform:

Resolution

The Lambda successfully receives requests to process from the Lambda runtime.


This is a 🐛 bug-report

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions