Add Client.close/1 that sends Refresh(lifetime=0). Release 0.2.2#10
Open
Add Client.close/1 that sends Refresh(lifetime=0). Release 0.2.2#10
Conversation
RFC 5766 §7.2 says a client gracefully releases its allocation by sending a Refresh request with LIFETIME=0. Without it the server keeps the 5-tuple bound until its own TTL expires (RFC default 600s), and a later Allocate from the same source port earns 437 Allocation Mismatch (§6.2). This deterministically reproduces against Cloudflare TURN when UDP source ports are cycled rapidly. Client.close/1 is a fire-and-forget emitter: the caller must ship the returned datagram on the same socket the allocation was established on before the socket is closed. The client transitions to :error on return, so any late response is ignored. Matches the teardown semantics in libwebrtc (TurnPort::Release), Pion (UDPConn.Close → refreshAllocation(0, dontWait=true)), and aiortc (TurnClientMixin.delete).
- Reuse refresh_request/5 (extended with optional Lifetime) from close/1 instead of inlining a near-identical Refresh construction. - Pin client.ref in cancel_timers/1 mailbox flushes so notifications destined for another ExTURN.Client in the same owning process are not consumed by mistake. - Trim Cloudflare-specific framing from the close/1 doc; the RFC-level rationale (5-tuple TTL, 437 on source-port reuse) stands on its own. - Add a :alloc-state test for close/1 covering the post-401, pre-success transition the catch-all clause handles. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #10 +/- ##
==========================================
+ Coverage 72.16% 74.32% +2.16%
==========================================
Files 8 8
Lines 273 296 +23
==========================================
+ Hits 197 220 +23
Misses 76 76
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
This was referenced May 5, 2026
Karolk99
approved these changes
May 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As reported by @joaothallis, we're not tearing down existing allocations like we ought to. This PR extends the API so that
ex_icemay cover this case and get rid of437 Allocation Mismatchresponses from the server.