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
Introduce "session_closed" handler callback #30945
Conversation
Introduce "session_closed" handler callback, and add support for CLOSE_WEBTRANSPORT_SESSION capsule. There is no conforming clients so it is not tested: I ran existing WPTs and confirmed this didn't break them. Also introduce WebTransportSession.dict_for_handlers to allow handlers to put arbitrary data to the associated session. This is different from Stash because Stash outlives sessions.
This is related to aiortc/aioquic#229 a bit. +@bashi for the overall change. cc: @DavidSchinazi @nidhijaju FYI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Some conforming questions.
@@ -225,6 +312,7 @@ def __init__(self, session: WebTransportSession, | |||
callbacks: Dict[str, Any]) -> None: | |||
self._session = session | |||
self._callbacks = callbacks | |||
self._allow_calling_session_closed = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about having _session_closed
flag in WebTransportH3Protocol or WebTransportSession. It is set when close() is called. session_closed() handler is bypassed when the _session_closed flag is set.
(I would like to keep this handler class a thin wrapper of an actual handler. Putting state management in WebTransportH3Protocol or WebTransportSession will help keeping this wrapper simple)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_session_closed
would need to be updated when session_closed
is called (it's also called in quic_event_received
). How would you update it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, in WebTransportSession, wouldn't
self._session_closed = True
in line 239- Add
maybe_notify_session_closed()
method. It callsself._handler.session_closed()
only whenself._session_closed = False
- Use
maybe_notify_session_closed()
where we currently callself._handler.session_closed()
work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about the latest change?
self.data = data | ||
|
||
@staticmethod | ||
def decode(data: bytes) -> any: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm, Is the reason you use any instead of H3Capsule to work around type checking in Python3.6?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using python3.8 but it complains at H3Capsule here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I thought PEP 563 should work for Python 3.8 but I forgot that we need to add from __future__ import annotations
to enable it. I dropped it since it didn't work for Python 3.6. Thank you for clarification.
@@ -225,6 +312,7 @@ def __init__(self, session: WebTransportSession, | |||
callbacks: Dict[str, Any]) -> None: | |||
self._session = session | |||
self._callbacks = callbacks | |||
self._allow_calling_session_closed = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, in WebTransportSession, wouldn't
self._session_closed = True
in line 239- Add
maybe_notify_session_closed()
method. It callsself._handler.session_closed()
only whenself._session_closed = False
- Use
maybe_notify_session_closed()
where we currently callself._handler.session_closed()
work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
self.data = data | ||
|
||
@staticmethod | ||
def decode(data: bytes) -> any: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I thought PEP 563 should work for Python 3.8 but I forgot that we need to add from __future__ import annotations
to enable it. I dropped it since it didn't work for Python 3.6. Thank you for clarification.
# TODO(yutakahirano): Implement the above. | ||
|
||
def call_session_closed(self, close_info: Optional[Tuple[int, bytes]], abruptly: bool) -> None: | ||
allow_calling_session_closed = self._allow_calling_session_closed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My mental model is that WebTransportSession has a state machine (e.g. not established, established, closed) and decides behavior based on the state so I slightly prefer to have an enum or _session_closed
flag, but this approach will also work.
@vasilvv can you take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The overall approach looks good to me; I've not looked closely at the parsing code, as I assume that will change when you add support for multiple capsules.
Thank you! I'm merging this. |
Introduce "session_closed" handler callback, and add support for CLOSE_WEBTRANSPORT_SESSION capsule. There is no conforming clients so it is not tested: I ran existing WPTs and confirmed this didn't break them. Also introduce WebTransportSession.dict_for_handlers to allow handlers to put arbitrary data to the associated session. This is different from Stash because Stash outlives sessions.
Introduce "session_closed" handler callback, and add support for
CLOSE_WEBTRANSPORT_SESSION capsule. There is no conforming
clients so it is not tested: I ran existing WPTs and confirmed
this didn't break them.
Also introduce WebTransportSession.dict_for_handlers to allow
handlers to put arbitrary data to the associated session. This is
different from Stash because Stash outlives sessions.