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 race conditions by switching to node webcrypto #396

Merged
merged 9 commits into from
Aug 7, 2024

Conversation

koush
Copy link
Collaborator

@koush koush commented Aug 5, 2024

builds on top of #395

certificate creation is async now, so the setupCertificate method needs to handle double calls correctly.

the main issue that was uncovered is that localDescription is now undefined when ice candidate gathering starts.

The underlying issue is that ice candidate gathering is being started during a setRemoteDescription offer. Werift (the answer peer) has not created an answer or called setLocalDescription at this point. But it has started gathering peers based on the offer side description.

const connected = this.iceTransports.find(
(transport) => transport.state === "connected",
);
if (this.remoteIsBundled && connected) {
// no need to gather ice candidates on an existing bundled connection
await connected.iceGather.gather();
} else {
await Promise.allSettled(
transports.map((iceTransport) => iceTransport.iceGather.gather()),
);
}

I believe this behavior is incorrect. Ice candidate gathering should only ever start during createAnswer and createOffer (or possibly setLocalDescription), as that is the typical spec/implementation. And that is also what is expected by onIceCandidate.

iceTransport.iceGather.onIceCandidate = (candidate) => {
if (!this.localDescription) return;
if (this.config.bundlePolicy === "max-bundle" || this.remoteIsBundled) {

@koush
Copy link
Collaborator Author

koush commented Aug 5, 2024

Another option is to queue the dropped candidates and flush them on setLocalDescription.

@koush
Copy link
Collaborator Author

koush commented Aug 6, 2024

I've fixed the underlying issue where setRemoteDescription is trigger candidating generation prior to createAnswer.

packages/webrtc/tests/utils.ts Outdated Show resolved Hide resolved
@koush
Copy link
Collaborator Author

koush commented Aug 7, 2024

I think this is finished now

@shinyoshiaki
Copy link
Owner

thanks!!

@shinyoshiaki shinyoshiaki merged commit 47b12fa into shinyoshiaki:develop Aug 7, 2024
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