Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better encapsulation for connection instances #353

Merged
merged 11 commits into from
Jun 9, 2021

Conversation

tomchristie
Copy link
Member

@tomchristie tomchristie commented Jun 8, 2021

This pull request introduces a refactoring to more tightly encapsulate Connection instances, so that the connection pool isn't reaching inside implementation details, but instead has a neat interface to work against. This'll be a precursor to further work on tightening up the implementation, ensuring we're more obviously guarded against potential race conditions, etc...

In addition to the existing handle_request and close methods, the interface the connection pool uses here are...

  • should_close - The connection has expired its keep alive, or been closed by the remote end.
  • is_idle - The connection is currently idle. It may optionally be removed from the pool, if needed.
  • is_closed - The connection is closed. It should be removed from the pool.
  • is_available - The connection is in a state where it can current accept another request.

An obvious stand-alone follow up to this would be to make other methods and attributes on the connection private.

@tomchristie tomchristie changed the title Better encapsulation for connection instanances Better encapsulation for connection instances Jun 8, 2021
@tomchristie
Copy link
Member Author

tomchristie commented Jun 8, 2021

Reading through this, one possible tweak that stands out... perhaps may_close should be is_idle?

EDIT: Done

Copy link
Member

@florimondmanca florimondmanca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gave it a quick look-over, really like the "hide the 'state' implementation details" idea. 👍

@tomchristie
Copy link
Member Author

Alrighty. I'm going to push ahead with this, and roll a new release.

We need to get this all into the wild particularly since we've switched to anyio as our default backend for asyncio.

There's a bunch of follow up I want to do from this one onwards, really tightening up any possible race condition areas, getting coverage all the way up, sorting out tls-over-tls support etc... and generally getting httpcore up to the same standard of quality that I feel the httpx repo is now in.

@tomchristie tomchristie merged commit 98fb2a0 into master Jun 9, 2021
@tomchristie tomchristie deleted the push-connection-interface-inside branch June 9, 2021 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants