I have an app running on AWS through ECS (as a Docker container) for which I used Suave to receive some REST commands.
The code is very primitive:
let conf =
{ defaultConfig with bindings = [ HttpBinding.createSimple HTTP "0.0.0.0" 80] }
let app =
choose
[
POST >=> choose
[
path "/" >=> request (fun m ->
// find if this is a subscription confirmation
let isConfirmation =
m.headers |> List.exists (fun kvp -> snd kvp = "SubscriptionConfirmation")
... more stuff here but that's it for the Suave code
and it is started with:
let listening, server = startWebServerAsync conf app
server |> Async.Start
listening |> Async.RunSynchronously |> ignore // wait for the server to start listening
At least once a day, Suave stops replying to any request and I get the following in the log:
(this is a screenshot because I couldn't get the text log out of the (super annoying) AWS's logging UI)
The error is always the same, and this is an app in testing with very little traffic. However, it gets a ping message every 10s from another app.
Since this is my first Suave project, how can I troubleshoot this? is this a known problem? is there more logging I can do to help troubleshoot it? could the issue be due to docker itself?
Edit:
I decided to print the connections used every 1 min:
there are 9 connections open
there are 15 connections open
there are 21 connections open
there are 26 connections open
there are 32 connections open
there are 37 connections open
there are 43 connections open
there are 49 connections open
there are 55 connections open
there are 61 connections open
there are 67 connections open
There is a ping received, as a POST message, every 10 seconds.
I track it this way:
let p = IPGlobalProperties.GetIPGlobalProperties().GetTcpIPv4Statistics()
terminal.BroadcastMessage $"there are {p.CurrentConnections} connections open"
It looks like the connections never gets closed.
This is just a guess, but I'm now able to reproduce this using PowerShell Invoke-WebRequest
across multiple terminals. Each new terminal I open causes the number of open connections to increase. It turns out that Invoke-WebRequest
uses a Keep-Alive
header by default, so I was able to fix the problem by disabling this feature.
Thus, I'm wondering if perhaps your client (the thing sending the ping) is using a keep-alive header, but failing to reuse the connections it opens. If so, you could fix this by disabling keep-alive in the client.