Repository navigation
Description
I have come across a strange issue when sending json log events using Serilog using the HTTP sink, but the issue will only appear if the receiving ASP.NET API is behind an F5 load balancer. The issue is that not all the data will be sent to the VIP on the F5 and the sending will hang until a timeout is reached (be that in IIS, httpClient timeout or F5 timeout).
I was able to get some POST's request to work by modifying the HTTP/2 profile on the F5 (https://support.f5.com/csp/article/K04412053), altering the Receive Window setting from the default 32kb, they only support a maximum of 128KB in this setting. That will work if I am sending say 50 events, but the default for the sink and what we would like to use is 1000 events. Due to the unknown size of what a list of events may be, I can not guarantee adjusting this receive window size would be a reasonable fix.
In summary:-
Sending API ->(HTTP/2)-> Receiving API - Works OK
Sending API ->(HTTP/1.1)-> Receiving API - Works OK
Sending API ->(HTTP/2)-> F5 VIP --> F5 Server Side ->(HTTP/2)-> Receiving API - Does Not Work
Sending API ->(HTTP/1.1)-> F5 VIP --> F5 Server Side ->(HTTP/2)-> Receiving API - Works OK
I have raised a case with F5 and they seem reluctant to investigate as they have used nghttp and are able to easily send 1000 events using HTTP/2 and indeed I can use curl to do the same, so they are saying this is pointing to aspnet rather than F5.
Example curl command that works fine
curl -vkX POST -H "Content-Type: application/json" -d @Events100.json https://IPADDRESS_HERE --http2
The original setup is using aspnetcore 3.1 web api that logs using serilog with the http sink to another aspnetcore 3.1 web api that will receive these serilog events and store them in a database.
For further testing I have created a simple dotnetcore 3.1 console application that will read a file (which just contains the events serilog would have been sending) and uses a httpClient to send to a basic aspnetcore 3.1 web api that will receive the data (not using IIS but just plain Kestrel) and write out to a file, this testing also fails with the timeout scenario.
This is all running on Windows Server 2019 Core.
For reference the events I am talking about are like this:-
{
"events": [
{
"Timestamp": "2021-05-05T10:25:32.5505666+00:00",
"Level": "Information",
"MessageTemplate": "HTTP {RequestMethod} {RequestPath} responded {StatusCode} in {Elapsed:0.0000} ms",
"RenderedMessage": "START - HTTP \"GET\" \"/weatherforecast\" responded 200 in 2.1560 ms",
"Properties": {
"RequestMethod": "GET",
"RequestPath": "/weatherforecast",
"StatusCode": 200,
"Elapsed": 2.156,
"SourceContext": "Serilog.AspNetCore.RequestLoggingMiddleware",
"RequestId": "80000812-0006-f800-b63f-84710c7967bb",
"SpanId": "|478ab71d-48fb709e612eba23.",
"TraceId": "478ab71d-48fb709e612eba23",
"ParentId": "",
"MachineName": "HOSTNAME_HERE",
"ThreadId": 9,
"Application": "APP_NAME_HERE"
},
"Renderings": {
"Elapsed": [
{
"Format": "0.0000",
"Rendering": "2.1560"
}
]
}
},
!-- x amount of more events here --!
]
}I do have wireshark traces that I have sent to F5 and can easily reproduce the issue. Before going on to that, is this the right place to raise this issue?
Also, is this going to be a battle of vendors where each one blames the other and the customer (me) doesn't get anywhere?
Activity
Tratcher commentedon May 5, 2021
Can you share the repro apps in a github repo so we can check for usage issues?
deathchurch commentedon May 5, 2021
Unfortunately I will not be able to put the original API's, but I have knocked together two test apps (Sender and Receiver) that when used together with the F5 demonstrate the same issue. Bear in mind the original API's are nothing like this and are more production focused rather than rough and ready as these two are, the repo can be found here:-
https://github.com/deathchurch/F5ASPNETISSUE
Thanks
Tratcher commentedon May 5, 2021
Notes from the repro:
The fact that it works when you change the client to use HTTP/1.1 to F5 implies an issue with the HttpClient, not the ASP.NET Server in the receiving API.
Next steps:
Are they decrypted? Encrypted traces aren't going to help here.
To rule out any issues on the server side you can also collect debug level logs from the receiving API, including decrypted wire content using the connection logging component in Kestrel: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel/endpoints?view=aspnetcore-5.0#connection-logging
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-5.0#configure-logging
If we don't see any obvious issues on the server side then I'll transfer you to https://github.com/dotnet/runtime for more HttpClient help.
deathchurch commentedon May 6, 2021
Thanks for the feedback, the test repo I threw together quickly to try and make it as simple as possible in the hope I could coerce F5 into testing with the same components rather than them just using curl/nghttp and saying everything was fine.
I can try using .NET 5
The more I look at this, I think I am coming to the same conclusion.
aspnetcore direct to aspnetcore works as expected with no issues.
Same issue, the Sending API and the VIP will not transfer all the event data and the request will hang until a timeout is fired.
Yes they are decrypted, the F5 can capture the whole end to end conversation (with keys) from Sending API to Receiving API. If you would like to look at them what is the best way of sending the traces to you?
I will give that a go yes.
Thanks for your time on this.
deathchurch commentedon May 6, 2021
Just to add I have tried the same tests with .NET 5 and the same issue occurs, I also have the debug logging from Kestrel enabled and also have wireshark traces that can be decrypted.
Tratcher commentedon May 6, 2021
You can attach the logs and traces to this issue or send them to the email in my profile.
Tratcher commentedon May 6, 2021
Logs:
Summary: The client (F5) aborts the connection mid body. There's no indication of an issue on the server. It looks like the server received 24648 bytes of body data before the connection died. That's way under kestrel's window limit of 96kb.
Failed Trace: tcp.stream eq 3
Success Trace: tcp.stream eq 1
So it looks like F5 isn't sending incremental Window Updates for the stream or connection, and the client is correctly waiting for those updates. This is clearly an issue with the F5 proxy. I'd be curious to see a matching trace from CURL.
deathchurch commentedon May 7, 2021
Thanks for the feedback, the RESET after 9 seconds (its closer to 10 seconds) is down to the fact in the Sender console app the httpClient is set by default to a timeout of 10 seconds, I can set this to a different value and it will just increase the delay in the traces. This is what we were seeing in the production API's, by default the httpClient didnt have a timeout and it was hitting the IIS timeout of ~110 seconds. As you say though, its not clear why there is a pause up to a timeout before sending the second data frame.
I will do a trace with curl and email over you the results.
Tratcher commentedon May 7, 2021
Curl trace: tcp.stream eq 0
So F5 is sending a window update in this scenario, which allows the client to continue the request.
Maybe that HttpClient 9s pause is the root issue here, it's failing to flush that data frame for some reason and F5 doesn't send a window update until the window is full.
Using .NET 5.0 I was able to reproduce this with Kestrel using a larger request body (100kb) to exceed kestrel's 96kb stream window size. I made the server avoid consuming the data and sending window updates, an the client times out.
The client sends 5 full frames, 80kb, and then waits for the timeout. Then it sends one more 16kb frame and the RST_STREAM together. 16kb would have put it right at the 96kb limit, but it still should have sent the data. It sounds like it doesn't flush if it hits the window limit.
I'm going to transfer this over to the HttpClient owners.
[-]Issues sending POST requests using HTTP/2 via F5 Load Balancer[/-][+]HttpClient Http/2 doesn't flush frames when hitting the window limit[/+]8 remaining items
karelz commentedon May 11, 2021
Triage: This is very weird F5 load balancer behavior. We should look at the code and if we think it affects other scenarios / other servers, then we should fix it. Otherwise move it to Future.
geoffkizer commentedon May 12, 2021
It may be weird behavior from F5, but it's still legal. It seems like we could hit this in other cases as well, it's just not nearly as likely.
It sounds like @Tratcher has diagnosed the problem:
If this analysis is correct, we should definitely fix this.
deathchurch commentedon May 21, 2021
Thanks @geoffkizer I think F5 were of the same opinion, they quoted https://datatracker.ietf.org/doc/html/rfc7540#section-5.2.1, and that on the client side they wait for the window to be filled before sending a window update, also they queried why they would they be expected to update the window if its not being used. I think they were open to any suggestions from Microsoft as to what they could improve.
I see you have a PR, hopefully that will resolve the problem, would that be targeted only to net6.0 or would that be available for net5.0 and netcore3.1?
Tratcher commentedon May 21, 2021
@karelz for the backport question. Since this is a client stall and an interop issue it is a good candidate for backport.
geoffkizer commentedon May 21, 2021
@deathchurch The current F5 behavior will result in poor performance. The client will send up to the window size, then it will need to wait until it gets a window update from the server. This will result in a stall in sending approx equal to the round trip time.
To improve performance, they should send window updates more frequently. Exactly how frequently is a somewhat complex question. For HttpClient, we send a window update for every approx (total window size / 8) bytes consumed by the app. I believe ASP.NET does something similar. But we're also looking at changing our receive window size heuristics for 6.0. There's not necessarily a perfect answer here, but what they are currently doing is definitely suboptimal.
karelz commentedon May 22, 2021
Given the above (the fact F5 uses something that leads to more problems), I wonder if we should backport our fix or not.
@deathchurch how much is it blocking you? If the fix is only in 6.0, are you able to consume it and use it to unblock yourself?
If we have more customers hitting it, I am all for backporting.
deathchurch commentedon May 24, 2021
@karelz our current policy is to be on the LTS version of framework, so moving to 6.0 would be a 2022 task, probably looking at 12-18 months of staying on 3.1. At the moment for a workaround wherever we have seen this issue, or potentially could see the issue we are having to explicitly set the client side profile on the F5 to only offer HTTP/1.1, the server side can still be HTTP/2, but it would be better to have the whole call chain as HTTP/2.
@geoffkizer I will pass those suggestions onto F5, in fact they might have already viewed this thread.
karelz commentedon May 25, 2021
Thanks @deathchurch for the context. Let's see if more customers are hit by this then.