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 packets do not honor configured DTLS MTU (attempt 3) #1345

Merged
merged 7 commits into from
Feb 27, 2024

Conversation

ibc
Copy link
Member

@ibc ibc commented Feb 27, 2024

Details

This PR is the same as PR #1156. However that PR introduced a memory leak (see issue #1340). This PR fixes that leak by following the discussion and research in associated issues and PRs, specially here: #1340 (comment)

To prove that this PR works at DTLS level, here the DTLS messages sent from mediasoup to browser while doing the DTLS handshake:

RTC::DtlsTransport::SendDtlsData() | 1349 bytes of DTLS data ready to be sent
RTC::DtlsTransport::SendDtlsData() | 1349 bytes of DTLS data ready to be sent
RTC::DtlsTransport::SendDtlsData() | 1349 bytes of DTLS data ready to be sent
RTC::DtlsTransport::SendDtlsData() | 1349 bytes of DTLS data ready to be sent
RTC::DtlsTransport::SendDtlsData() | 1349 bytes of DTLS data ready to be sent
RTC::DtlsTransport::SendDtlsData() | 242 bytes of DTLS data ready to be sent
RTC::DtlsTransport::SendDtlsData() | 67 bytes of DTLS data ready to be sent
RTC::DtlsTransport::SendDtlsData() | 129 bytes of DTLS data ready to be sent
RTC::DtlsTransport::SendDtlsData() | 385 bytes of DTLS data ready to be sent
RTC::DtlsTransport::SendDtlsData() | 45 bytes of DTLS data ready to be sent

which clearly corresponds to what we see in Wireshark (there is a huge certificate so it's splitted into N DTLS Certificate fragments):

CleanShot-2024-02-27-at-16 51 19@2x

Note that sizes of each message match the DTLS data sent by mediasoup plus UDP and IP encapsulation (32 bytes always).

- Fixes #1100
- Based on PR #1156 which was based on PR #1143

### Details

This PR is the same as PR #1156. However that PR introduced a memory leak (see issue #1340). This PR fixes that leak by following the discussion and research in associated issues and PRs, specially here: #1340 (comment)
@ibc
Copy link
Member Author

ibc commented Feb 27, 2024

CC @gkrol-katmai @pnts-se

worker/src/RTC/DtlsTransport.cpp Show resolved Hide resolved
worker/src/RTC/DtlsTransport.cpp Outdated Show resolved Hide resolved
worker/src/RTC/DtlsTransport.cpp Outdated Show resolved Hide resolved
Copy link
Member

@jmillan jmillan left a comment

Choose a reason for hiding this comment

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

👍 👍

@gkrol-katmai
Copy link

The code looks good to me! I think we now have a good grasp of what's going on. I know that adding the 'reset' in that function will fix the leak. I haven't tested this PR.

Not sure what the coding standards are for comments, but I would suggest we add comments to onSslBioOut and DtlsTransport::SendDtlsData (above the implementation). Those should describe the effect of the function and when/why it gets called. Preferably /** */ style. We're doing some subtle things here so we need to be extra clear.

@ibc
Copy link
Member Author

ibc commented Feb 27, 2024

I know that adding the 'reset' in that function will fix the leak. I haven't tested this PR.

I think this is also proven here #1340 (comment) where it's clear that the onSslBioOut is always called with len matching the previous mem_write() call.

Not sure what the coding standards are for comments, but I would suggest we add comments to onSslBioOut and DtlsTransport::SendDtlsData (above the implementation). Those should describe the effect of the function and when/why it gets called. Preferably /** */ style. We're doing some subtle things here so we need to be extra clear.

Done here: e827248

@ibc
Copy link
Member Author

ibc commented Feb 27, 2024

BTW I've added some logs and Wireshark capture in the PR description above proving that everything makes sense.

@ibc
Copy link
Member Author

ibc commented Feb 27, 2024

Let's merge and release. Thanks a lot.

@ibc ibc merged commit 9af2a26 into v3 Feb 27, 2024
22 checks passed
@ibc ibc deleted the fix-dtls-mtu-issue-1100-attempt-3 branch February 27, 2024 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

DTLS fragment exceeds MTU size if the certificate is large.
3 participants