Skip to content

small fixes: hash's MSVC ARM64 C4324 and constinit canaries; webrtc's native races and cleanup hang (libdatachannel patches) - #56

Merged
pinhopro merged 6 commits into
mainfrom
fix/small-fixes
Nov 24, 2026
Merged

pinhopro merged 6 commits into
mainfrom
fix/small-fixes

Conversation

@pinhopro

Copy link
Copy Markdown
Contributor

Three small fixes, with the libdatachannel corrections that the third one needed.

  • webcpp::hash (hash#12, merged as eed3aab). MSVC ARM64's C4324 is turned off for the hasher. libsodium's CRYPTO_ALIGN states force trailing padding, and MSVC for ARM64 (but not x64) reports that padding under /W4 /WX; a probe on 14.3 and 14.5 showed identical layouts on both architectures. The backends' canaries are declared constinit instead of carrying NOLINT. Verified: native clang, gcc and Emscripten lanes; MSVC 14.3 and 14.5 ARM64 (743 passed each, hash plus crypto tests).
  • webcpp::webrtc flaky native.run (a_full_exchange). tools/libdatachannel/build.py applies tools/libdatachannel/patches to its verified staged copy:
    • dtls-mtu-before-incoming.patch: the DTLS server answered a ClientHello kept from before start() while its MTU was unset, and the handshake failed. Upstream fixed this on master in 0bdce84 (2026-11-19); the patch goes away once a release with it is pinned.
    • sctp-init-once.patch: two threads each created an SCTP transport, and the replaced one stopped DTLS. Upstream master has no fix.
    • Before: macOS 6/2100 and 6/9000 under load; MSVC 14.5 x64 1 to 1.5% (29/3200). After: 0 connection failures in 24000 macOS runs and in thousands of MSVC runs.
  • A hang found while repeating the test on MSVC 14.5 (about 1 run in 3700, present without the patches too). After rtcCleanup() timed out, the next rtcPreload() waited forever: libdatachannel's SctpTransport::Cleanup() spun under the init lock while usrsctp held an endpoint.
    • usrsctp-iterator-restart.patch (a usrsctp bug, with a deterministic reproducer): after usrsctp_finish() and usrsctp_init(), the iterator thread exited at once, and a queued iterator held its endpoint forever.
    • sctp-cleanup-bounded.patch (a mitigation): an association that usrsctp leaves with no timer and no reference (mechanism not identified, reported upstream) is leaked after 5 s instead of hanging the process. The owner's decision on shipping this mitigation is pending: do not merge before it.

Verification on this tree (f3ac5ff): native webrtc lanes on clang, gcc and Emscripten; macOS lint clean; full Linux lint CLEAN; MSVC webrtc 14.3 and 14.5 x64 (36 passed each); 14.5 repeat runs (see HANDBACK). The guidelines' D16 ("libdatachannel unmodified") is amended, pending the owner's approval.

R added 6 commits November 23, 2026 17:06
… for two races of 0.24.6 that failed a native connection about once in 300 runs under load

webcpp::webrtc's native test failed once on MSVC 14.3 (a_full_exchange: no channel, the state
never connected). Under load on macOS the native tests failed 6 of 2100 runs, each an exchange
whose connection went to failed, and libdatachannel's log named two races of the offerer, whose
ICE transport starts while rtcSetRemoteDescription applies the answer:

- DtlsTransport::start() registered its incoming callback, which replays the records the ICE
  transport kept, before setting the DTLS MTU; doRecv could answer the peer's ClientHello first,
  and OpenSSL, with SSL_OP_NO_QUERY_MTU and no MTU, failed the write (SSL_ERROR_SYSCALL,
  "Handshake failed: fatal I/O error"). dtls-mtu-before-incoming.patch sets the MTU first.
- initSctpTransport() checked and created without a lock, so the DTLS Connected callback and
  processRemoteDescription() each made an SCTP transport, and the replaced one, destroyed,
  stopped DTLS. sctp-init-once.patch gives it a mutex, as initDtlsTransport() has.

build.py applies tools/libdatachannel/patches/*.patch, by name, to the verified staged copy
alone (the checkout and the archive stay upstream's), refuses one that touches anything but
src/, one the sources hold already and one that no longer applies; the patches are inputs of
the configuration's key. With both, 12000 runs under the same load failed none. Each patch is
under libdatachannel's MPL-2.0. The guidelines' "unmodified" decision (D16) is amended pending
the owner's approval.
…d constinit fixes and of webrtc's libdatachannel notes (eed3aab, fc1f57a)
…rsctp's iterator thread, for a native test that hung about once in 3000 runs on MSVC

webcpp::webrtc's native test makes and destroys a runtime per test. On MSVC 14.5 x64 it hung
about once in 3000 to 4000 runs, without the earlier patches too. The dumps showed the main
thread in rtcPreload() waiting for libdatachannel's initialization lock, and the cleanup thread
holding that lock in SctpTransport::Cleanup(), which calls usrsctp_finish() until it succeeds
while usrsctp holds one endpoint it never frees:

- usrsctp keeps its iterator thread's MUST_EXIT and EXITED flags across usrsctp_finish() and
  usrsctp_init(), so after the first cleanup each new iterator thread exits at once, and an
  iterator queued afterwards (the address work queue) holds its endpoint forever. The dumps
  showed the flags at 3, no iterator thread and an iterator holding that endpoint; a small
  program over the pinned libusrsctp.a reads the flags at 3 after a second usrsctp_init(), and
  at 0 with usrsctp-iterator-restart.patch, which clears them when the thread starts.
- With that fixed, an association whose free began on the SHUTDOWN-ACK path was still left, in
  one run of about 9600, with no timer and no reference to free it (the dumps show states no
  single path reaches; upstream is told, with no fix). sctp-cleanup-bounded.patch bounds the
  SCTP cleanup to five seconds, within rtcCleanup()'s ten: usrsctp then stays initialized for the
  next initialization, which uses it, and the endpoint leaks instead of the process hanging.

build.py lets a patch change the pinned usrsctp's sources (deps/usrsctp/usrsctplib/) besides
libdatachannel's src/; each patch is under the licence of the files it changes.
… usrsctp corrections (local, for the lanes)
…p and usrsctp corrections and the native test's guarded checks (d8bcf37)
@pinhopro
pinhopro merged commit 3ba8d98 into main Nov 24, 2026
2 of 12 checks passed
@pinhopro
pinhopro deleted the fix/small-fixes branch November 24, 2026 06:50
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.

1 participant