Skip to content

Fix NewUDPMuxDefault panic#900

Open
FrantaBOT wants to merge 1 commit intomasterfrom
fix-newudpmuxdefault-panic
Open

Fix NewUDPMuxDefault panic#900
FrantaBOT wants to merge 1 commit intomasterfrom
fix-newudpmuxdefault-panic

Conversation

@FrantaBOT
Copy link

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
Copy link

codecov bot commented Mar 14, 2026

Codecov Report

❌ Patch coverage is 0% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.18%. Comparing base (398ac7c) to head (672963f).

Files with missing lines Patch % Lines
error_conn.go 0.00% 11 Missing ⚠️
udp_mux.go 0.00% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #900      +/-   ##
==========================================
- Coverage   88.37%   88.18%   -0.19%     
==========================================
  Files          44       45       +1     
  Lines        5591     5605      +14     
==========================================
+ Hits         4941     4943       +2     
- Misses        451      461      +10     
- Partials      199      201       +2     
Flag Coverage Δ
go 88.18% <0.00%> (-0.19%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 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
var localAddrsForUnspecified []net.Addr
if udpAddr, ok := params.UDPConn.LocalAddr().(*net.UDPAddr); !ok { //nolint:nestif
//nolint:nestif
if params.UDPConn == nil {
Copy link
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
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.

Copy link
Author

@FrantaBOT FrantaBOT Mar 14, 2026

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
Copy link
Member

@JoTurk JoTurk left a comment

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
Copy link
Contributor

asayyah commented Mar 14, 2026

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

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.

3 participants