Skip to content
This repository was archived by the owner on Jul 18, 2023. It is now read-only.

Socket issues when re-creating LineProtocolClient a lot #73

@jakkaj

Description

@jakkaj

This issue arises when re-creating the LineProtocolClient a lot.

ERROR [24-07-2019 15:10:21]: System.Net.Http.HttpRequestException: Address already in use ---> System.Net.Sockets.SocketException: Address already in use at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken) at System.Threading.Tasks.ValueTask1.get_Result()
at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Threading.Tasks.ValueTask1.get_Result() at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask1 creationTask)
at System.Threading.Tasks.ValueTask1.get_Result() at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
at InfluxDB.LineProtocol.Client.LineProtocolClient.SendAsync(String payload, Precision precision, CancellationToken cancellationToken)
at EnergyHost.Services.Services.InfluxService.Write(String db, String measurement, IReadOnlyDictionary2 data, IReadOnlyDictionary2 tags, Nullable1 utcTimeStamp) in /app/EnergyHost.Services/Services/InfluxService.cs:line 82 ERROR [24-07-2019 15:10:21]: System.Net.Http.HttpRequestException: Address already in use ---> System.Net.Sockets.SocketException: Address already in use

It appears related to this: https://github.com/dotnet/corefx/issues/37044.

A solution may be this: https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests - although at this time it does not appear to be usable in netstandard2.0 without the addition of dependency injection in to the project.

It's hard to share a single LineProtocolClient across a lot of requests as the constructor takes the database name. The developer could create a little factory to handle this, which I plan to do - but it would be nice if the underlying usage of HttpClient handled this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions