Skip to content

Add errors to muxes - #900

Open
FrantaBOT wants to merge 1 commit into
mainfrom
fix-newudpmuxdefault-panic
Open

FrantaBOT wants to merge 1 commit into
mainfrom
fix-newudpmuxdefault-panic

Conversation

@FrantaBOT

Copy link
Copy Markdown

Description

Fixes a edge case where attempting to call the NewUDPMuxDefault function with UDPConn being nil it would cause a panic.

Unfortunately, this function does not return an error and never returns nil, so there is no clearway to prevent this.

@FrantaBOT
FrantaBOT requested a review from JoTurk March 14, 2026 17:50
@codecov

codecov Bot commented Mar 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.87500% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.70%. Comparing base (9dffa80) to head (f621e5f).

Files with missing lines Patch % Lines
udp_mux_multi.go 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #900      +/-   ##
==========================================
+ Coverage   91.69%   91.70%   +0.01%     
==========================================
  Files          45       45              
  Lines        5479     5498      +19     
==========================================
+ Hits         5024     5042      +18     
- Misses        455      456       +1     
Flag Coverage Δ
go 91.70% <96.87%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@FrantaBOT
FrantaBOT force-pushed the fix-newudpmuxdefault-panic branch from e2a5c24 to 00c255f Compare March 14, 2026 18:02
@FrantaBOT
FrantaBOT requested a review from Juliapixel March 14, 2026 18:05
@FrantaBOT
FrantaBOT force-pushed the fix-newudpmuxdefault-panic branch from 00c255f to 0072963 Compare March 14, 2026 18:27
Comment thread errors.go Resolved
Comment thread udp_mux.go Outdated
var localAddrsForUnspecified []net.Addr
if udpAddr, ok := params.UDPConn.LocalAddr().(*net.UDPAddr); !ok { //nolint:nestif
//nolint:nestif
if params.UDPConn == nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems an odd way of going around UDPConn being nil. You end up creating a broken mux. Could you share more context on what's causing UDPConn to be nil in the first place? This seems like it should be handled on the caller

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is just because we can't introduce err to the constructor without breaking the API, user/dev errors shouldn't cause a panic, I think @FrantaBOT 's workaround is okay, idk.

@FrantaBOT FrantaBOT Mar 14, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Could you share more context on what's causing UDPConn to be nil in the first place?

I want to prevent panic crash from improper use by any developer.

You end up creating a broken mux

Mux returning error is better outcome then panicking.

@FrantaBOT
FrantaBOT force-pushed the fix-newudpmuxdefault-panic branch from 0072963 to 672963f Compare March 14, 2026 20:06

@JoTurk JoTurk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What if we make a new mux constructor with options patterns, and with errors, and deprecate this one?

@asayyah

asayyah commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

Yeah I like constructor with options patterns much better, this to me seems like we are hiding a problem and moving along with a semi-broken system? I don't know enough about the expected behavior from the system though

@Sean-Der

Copy link
Copy Markdown
Member

Closing since we can't fix it without breaking Mux API

Another PITA is that this has pion/webrtc use. Should have abstracted it away :/

@Sean-Der Sean-Der closed this Sep 22, 2026
@Sean-Der
Sean-Der deleted the fix-newudpmuxdefault-panic branch September 22, 2026 16:48
@JoTurk
JoTurk restored the fix-newudpmuxdefault-panic branch October 11, 2026 09:33
@JoTurk

JoTurk commented Oct 11, 2026

Copy link
Copy Markdown
Member

@FrantaBOT @Sean-Der since we're doing v5 we can reopen this I think, muxes should be able to return errors, this also can be used to return an error for the IPv6 DAD issues i talked about in discord. https://discord.com/channels/1352636971591274548/1359189787768258671/1551698660897726485

@FrantaBOT mind if you change this PR to make all the muxes return errors?

@JoTurk JoTurk reopened this Oct 11, 2026
@FrantaBOT FrantaBOT changed the title Fix NewUDPMuxDefault panic Fix missing error return Dec 2, 2026
@FrantaBOT FrantaBOT changed the title Fix missing error return Add errors to muxes Dec 2, 2026
@FrantaBOT FrantaBOT closed this Dec 2, 2026
@FrantaBOT
FrantaBOT force-pushed the fix-newudpmuxdefault-panic branch from 672963f to 9dffa80 Compare December 2, 2026 18:39
@FrantaBOT FrantaBOT reopened this Dec 2, 2026
@FrantaBOT
FrantaBOT force-pushed the fix-newudpmuxdefault-panic branch from 11841b4 to 9761eae Compare December 2, 2026 20:33
@FrantaBOT
FrantaBOT requested a review from JoTurk December 2, 2026 20:34
Comment thread errors.go Outdated
Comment on lines +118 to +137
// ErrNoTCPMux indicates that no TCPMux was provided to NewMultiTCPMuxDefault.
ErrNoTCPMux = errors.New("at least one TCPMux is required")

// ErrNilTCPMux indicates that a nil TCPMux was provided to NewMultiTCPMuxDefault.
ErrNilTCPMux = errors.New("TCPMux must not be nil")

// ErrNoUDPMux indicates that no UDPMux was provided to NewMultiUDPMuxDefault.
ErrNoUDPMux = errors.New("at least one UDPMux is required")

// ErrNilUDPMux indicates that a nil UDPMux was provided to NewMultiUDPMuxDefault.
ErrNilUDPMux = errors.New("UDPMux must not be nil")

// ErrNilTCPMuxParamsListener is returned when TCPMuxParams.Listener is nil.
ErrNilTCPMuxParamsListener = errors.New("TCPMuxParams.Listener must not be nil")

// ErrNilUDPMuxParamsUDPConn is returned when UDPMuxParams.UDPConn is nil.
ErrNilUDPMuxParamsUDPConn = errors.New("UDPMuxParams.UDPConn must not be nil")

// ErrNilUniversalUDPMuxParamsUDPConn is returned when UniversalUDPMuxParams.UDPConn is nil.
ErrNilUniversalUDPMuxParamsUDPConn = errors.New("UniversalUDPMuxParams.UDPConn must not be nil")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please make these errors private

@FrantaBOT
FrantaBOT force-pushed the fix-newudpmuxdefault-panic branch from 9761eae to 4f1a484 Compare December 3, 2026 16:10
@FrantaBOT
FrantaBOT requested a review from JoTurk December 3, 2026 16:10
@FrantaBOT
FrantaBOT force-pushed the fix-newudpmuxdefault-panic branch from 4f1a484 to f621e5f Compare December 3, 2026 16:16
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.

4 participants