Skip to content

How to extend connection timeout #4258

@iradization

Description

@iradization

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google "How to X in FastAPI" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

@app.post("/heartbeat")
async def get_heartbeat(request: Request):
    print(request)

Description

I expect to reuse my connection to send heartbeat message every 10 seconds from the client side, but it gets disconnected by peer (server in this case) for every new message os i need to create a new one.

Operating System

macOS

Operating System Details

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 so it can be reused.

However, on the client part I see that for 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 set, but it is entirely up to the server how long it will keep the connection alive. is it an expected behavior ?
Is there any suitable way to extend this timeout to at least 10 minutes ?
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

FastAPI Version

0.70.0

Python Version

3.9.7

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions