Fix TURN CreatePermission panic in stun crate Display impl#169
Closed
Fix TURN CreatePermission panic in stun crate Display impl#169
Conversation
…play impl The stun crate's ErrorCodeAttribute::Display implementation panics when the error reason contains non-UTF-8 bytes, because format!() panics when a Display impl returns Err(fmt::Error). This patch uses from_utf8_lossy() instead, which surfaces the actual TURN error gracefully rather than panicking. This fixes WebRTC connection failures where the TURN relay setup panic killed the connection attempt, resulting in "unknown service viam.robot.v1.RobotService" errors on fallback. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
stuncrate'sErrorCodeAttribute::Displayimplementation to useString::from_utf8_lossy()instead ofString::from_utf8(), which panics viaformat!()when the TURN error reason contains non-UTF-8 bytes.create_permissionskills the TURN relay setup, causing a timeout and fallback to direct gRPC throughapp.viam.com, which returnsunknown service viam.robot.v1.RobotService.Root Cause
The
stun-0.7.0crate'sErrorCodeAttribute::DisplayreturnsErr(fmt::Error)when the error reason bytes aren't valid UTF-8. Rust'sformat!()macro panics when aDisplayimpl returns an error ("a formatting trait implementation returned an error"). This is triggered inturn-0.9.0/src/client/relay_conn.rs:436duringcreate_permissions.The upstream
stun/turncrates are archived and unmaintained (webrtc-rs), so a local patch via[patch.crates-io]is the appropriate fix.Test plan
libviam_rust_utils.dyliblocallymugger1-main) via WebRTC🤖 Generated with Claude Code