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

Ensure H2 state is only accessed by the connection, not per-stream. #628

Merged
merged 2 commits into from
Dec 12, 2019

Conversation

tomchristie
Copy link
Member

This refactor moves all the H2 state management onto the Connection class, rather than being per-stream.

I think we'll want to eventually move our stream-locks out of the stream implementation and onto HTTP2Connection instead, so eg...

async with self.write_lock:  # Ensure that outgoing data cannot get sent out-of-sequence.
    data_to_send = self.state.data_to_send()
    await self.socket.write(data_to_send, timeout)

@tomchristie tomchristie added http/2 Issues and PRs related to HTTP/2 refactor Issues and PRs related to code refactoring labels Dec 11, 2019
@florimondmanca
Copy link
Member

I think we'll want to eventually move our stream-locks out of the stream implementation and onto HTTP2Connection instead

It's probably a good idea, provided those locks were indeed added to solve issues for HTTP/2. (It was the case for the read_lock - see #527. For write_lock, I think we only have it on trio for now - it was added as part of #276, and I think that was also to fix an HTTP/2 concurrency issue, see #276 (comment).)

@tomchristie
Copy link
Member Author

Thanks, those are great pointers.

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.

Sounds good! 🎉

connection: HTTP2Connection,
state: h2.connection.H2Connection,
) -> None:
def __init__(self, stream_id: int, connection: HTTP2Connection,) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

Formatting nit (I've already had these, not sure why Black doesn't reformat them):

Suggested change
def __init__(self, stream_id: int, connection: HTTP2Connection,) -> None:
def __init__(self, stream_id: int, connection: HTTP2Connection) -> None:

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

https://github.com/psf/black#trailing-commas was changed recently, I believe psf/black#826 was the culprit responsible PR. There appears to be a follow-up PR psf/black#1164 to remedy it.

@tomchristie tomchristie merged commit 1d25bd5 into master Dec 12, 2019
@tomchristie tomchristie deleted the http2-state-on-connection-only branch December 12, 2019 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http/2 Issues and PRs related to HTTP/2 refactor Issues and PRs related to code refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants