Skip to content

What are the possible consequences of reusing the same session throughout the app? #2719

Answered by tomchristie
zmievsa asked this question in Q&A
Discussion options

You must be logged in to vote

We open the session at the beginning of a fastapi process and never close it.

Great! Use a single client all the way through the lifetime of your process is how you want it. You'll get proper connection pooling throughout that way.

Note that I understand that httpx recommends always closing the session and now I'm just trying to understand the reasons behind this

I'm not sure how much it matters, you'd need to really dig into the differences between how the outstanding TCP connections are closed depending on when you do explicitly close the connection pool at the end of it's lifespan vs. when you just quit the Python process.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by zmievsa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants