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

Fix dtls handshake potential hanging issue #631

Merged

Conversation

mutexd
Copy link
Contributor

@mutexd mutexd commented Nov 17, 2024

  • The logic of handshake_tx is copied from Pion::dtls. However, tokio:: mpsc::channel with size 1 is used here, and it behaves differently from the golang::channel. The golang channel is actually a rendezvous channel (size=0 channel). It means that the sender blocks until the receiver receives, then both of them can proceed. However, the tokio::mpsc::sender can proceed as long as there is capacity in the channel. Channel with size=1 is not a rendezvous channel and tokio::mpsc::channel doesn't support size=0.
  • Therefore, I added an async block where oneshot channel is integrated in order to mimic the rendezvous channel behavior. The handshake_rx has to send the message back to oneshot channel after leave recv(), so that the handshake_tx can leave the rendezvous.
  • I tried to search for another crate which supports size=0 channel, such as flume, but it doesn't make sense to me to use another create which provides similar functions that tokio provides. Thus, I would suggest this bugfix as a solution, other than solutions deviating too much from Pion::dtls, which seems to be robust.

This bugfix addresses issue #628

- The logic of handshake_tx is copied from Pion::dtls. However, tokio:: mpsc::channel with size 1 is used here, and it behaves differently from the golang::channel. The golang channel is actually a rendezvous channel (size=0 channel). It means that the sender blocks until the receiver receives, then both of them can proceed. However, the tokio::mpsc::sender can proceed as long as there is capacity in the channel. Channel with size=1 is not a rendezvous channel and tokio::mpsc::channel doesn't support size=0. therefore, I added an async block where oneshot channel is integrated in order to mimic the rendezvous channel behavior.
@rainliu rainliu merged commit c4f4031 into webrtc-rs:master Nov 17, 2024
4 of 5 checks passed
tubzby pushed a commit to tubzby/webrtc-rs that referenced this pull request Nov 26, 2024
- The logic of handshake_tx is copied from Pion::dtls. However, tokio:: mpsc::channel with size 1 is used here, and it behaves differently from the golang::channel. The golang channel is actually a rendezvous channel (size=0 channel). It means that the sender blocks until the receiver receives, then both of them can proceed. However, the tokio::mpsc::sender can proceed as long as there is capacity in the channel. Channel with size=1 is not a rendezvous channel and tokio::mpsc::channel doesn't support size=0. therefore, I added an async block where oneshot channel is integrated in order to mimic the rendezvous channel behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants