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

Introduce "session_closed" handler callback #30945

Merged
merged 10 commits into from Sep 28, 2021

Conversation

yutakahirano
Copy link
Contributor

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.
@yutakahirano
Copy link
Contributor Author

This is related to aiortc/aioquic#229 a bit.

+@bashi for the overall change.
+@vasilvv for the logic in _h3_event_received and WebTransport.session. Am I using capsule correctly?

cc: @DavidSchinazi @nidhijaju FYI

Copy link
Member

@bashi bashi left a 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.

tools/webtransport/h3/webtransport_h3_server.py Outdated Show resolved Hide resolved
@@ -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
Copy link
Member

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)

Copy link
Contributor Author

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?

Copy link
Member

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 calls self._handler.session_closed() only when self._session_closed = False
  • Use maybe_notify_session_closed() where we currently call self._handler.session_closed()
    work?

Copy link
Contributor Author

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?

webtransport/connect.any.js Outdated Show resolved Hide resolved
self.data = data

@staticmethod
def decode(data: bytes) -> any:
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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
Copy link
Member

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 calls self._handler.session_closed() only when self._session_closed = False
  • Use maybe_notify_session_closed() where we currently call self._handler.session_closed()
    work?

tools/webtransport/h3/webtransport_h3_server.py Outdated Show resolved Hide resolved
tools/webtransport/h3/webtransport_h3_server.py Outdated Show resolved Hide resolved
Copy link
Member

@bashi bashi left a 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:
Copy link
Member

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
Copy link
Member

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.

@yutakahirano
Copy link
Contributor Author

@vasilvv can you take a look?

Copy link
Contributor

@vasilvv vasilvv left a 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.

@yutakahirano
Copy link
Contributor Author

Thank you! I'm merging this.

@yutakahirano yutakahirano merged commit 96b23e1 into master Sep 28, 2021
@yutakahirano yutakahirano deleted the yhirano/webtransport-session-closed branch September 28, 2021 04:02
Gabisampaio pushed a commit to Gabisampaio/wpt that referenced this pull request Nov 18, 2021
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants