NLog.Targets.HTTP icon indicating copy to clipboard operation
NLog.Targets.HTTP copied to clipboard

Port Exhaustion on .NET 5

Open scottsauber opened this issue 3 years ago • 8 comments

Using this target on .NET 5 appears to eat up ports. We are hitting the 128 port limit out on Azure App Service when we have this target turned on. It's not immediately obvious to me how we can mitigate this, so wanted to start the conversation.

scottsauber avatar Jan 11 '22 05:01 scottsauber

Acknowledged. Can you provide your configuration setup without the sensitive parts, please?

DarekDan avatar Jan 11 '22 22:01 DarekDan

<target name='TargetName'
            type='HTTP'
            URL='urlhere'
            Method='POST'
            BatchSize='1'
            MaxQueueSize='2147483647'
            IgnoreSslErrors='true'
            FlushBeforeShutdown='true'
            ContentType='application/json'
            Accept='application/json'
            DefaultConnectionLimit='2'
            Expect100Continue='false'
            UseNagleAlgorithm='true'
            ConnectTimeout='30000'
            InMemoryCompression='true'
        >
        </target>

scottsauber avatar Jan 12 '22 03:01 scottsauber

We are also seeing a similar issue with high port utilization and occasional exhaustion in Azure App Service with essentially the same configuration. We are running on .NET Core 3.1 though. Currently have deployed with version 1.0.10 of NLog.Targets.HTTP as there were unresolved issues at the last update with newer versions (since resolved).

ghost avatar Jan 14 '22 18:01 ghost

Acknowledged. Rough week at work. Will look into it over the weekend.

DarekDan avatar Jan 14 '22 18:01 DarekDan

Hey @DarekDan any update here? No worries if you’ve been busy.

scottsauber avatar Jan 31 '22 14:01 scottsauber

Hey @DarekDan any update on this?

scottsauber avatar Feb 21 '22 14:02 scottsauber

Hey, I ran into the same problem last weekend with an automated service (.NET6) I'm not sure, but i assume, that there is a chance, that the ResetHttpClientIfNeeded Method spawns rapidly SocketHttpHandler and this is causing the issue. A simple _httpClient?.Dispose() could help Also HTTP should override the Dispose to at least call _httpClient.Dispose()

Even if it does not fix the issue, it's at least a good practice 😄

Created a PR for this: https://github.com/DarekDan/NLog.Targets.HTTP/pull/43

TieHummingDev avatar Mar 28 '22 12:03 TieHummingDev

Just looked again at it. Maybe this is the problem here. This should be quite easy to implement. But i don't know, if the owner want this kind of solution (mainly cause of a new depandency, Microsoft.Extensions.Http ).

TieHummingDev avatar Mar 29 '22 07:03 TieHummingDev