I'm using fastAPI python framework to build a simple POST/GET https server. On the client side, i send heartbeat POST messages every 10 seconds and i'd like to keep my connection open during this period.
However, for some reason I see that every new heartbeat, my connection get disconnected by the peer, so I need to re-establish it. If the idle period between 2 consecutive keepalives is 1 second, the Connection remains active, and can be reused.
I'm using HTTP/1.1
with Connection: keep-alive
, but it is entirely up to the server how long it will keep the connection alive, and I'm looking for a way to extend this timeout to ~15 seconds. is there any suitable way to do it ? or even just make the server print proper log message when it decide to disconnect the client peer ...
P.S. in order to start the server I'm using the following command, Perhaps it need to be modified ?
uvicorn main:app --port 44444 --host 0.0.0.0 --reload --ssl-keyfile ./key.pem
--ssl-certfile ./certificate.pem --log-level debug
CodePudding user response:
From the uvicorn docs:
--timeout-keep-alive <int> - Close Keep-Alive connections if no new data is received within this timeout. Default: 5.
But it‘s probably no great idea to set this to 10 minutes. What is your problem with dropping the connection for a heartbeat?