Skip to content

Fix UDPMuxDefault not reflecting network changes#926

Merged
aler9 merged 1 commit into
pion:mainfrom
aler9:fix/udp-localaddrs
Jun 4, 2026
Merged

Fix UDPMuxDefault not reflecting network changes#926
aler9 merged 1 commit into
pion:mainfrom
aler9:fix/udp-localaddrs

Conversation

@aler9

@aler9 aler9 commented Jun 2, 2026

Copy link
Copy Markdown
Member

Description

UDPMuxDefault was internally caching the list of local IPs, making connectivity impossible after a network change or a local IP change. This was also redundant given the fact that IPs and interfaces are already cached by their provider, which is stdnet.Net / transport.Net.

This patch removes this cache layer, allowing UDPMuxDefault to receive upstream interface and IP changes, and fixing support for network changes.

Reference issue

bluenviron/mediamtx#5097

@codecov

codecov Bot commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.64706% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.19%. Comparing base (22d7d42) to head (730d8f2).

Files with missing lines Patch % Lines
udp_mux.go 69.69% 7 Missing and 3 partials ⚠️
udp_mux_multi.go 0.00% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (67.64%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #926      +/-   ##
==========================================
- Coverage   88.35%   88.19%   -0.16%     
==========================================
  Files          46       46              
  Lines        5969     5973       +4     
==========================================
- Hits         5274     5268       -6     
- Misses        481      490       +9     
- Partials      214      215       +1     
Flag Coverage Δ
go 88.19% <67.64%> (-0.16%) ⬇️

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.

@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.

The idea of removing the cache interface looks good to me, maybe we need to make a small helper for detecting network changes across different systems in pin/transport, so we don't have to relay on library logic or polling, this was the plan for nomination anyways.

@cnderrauber this reverts some of a931199 does it look good for you?

Comment thread udp_mux.go
Comment on lines 47 to 73
@@ -61,50 +61,24 @@ type UDPMuxParams struct {
}

// NewUDPMuxDefault creates an implementation of UDPMux.
func NewUDPMuxDefault(params UDPMuxParams) *UDPMuxDefault { //nolint:cyclop
func NewUDPMuxDefault(params UDPMuxParams) *UDPMuxDefault {
if params.Logger == nil {
params.Logger = logging.NewDefaultLoggerFactory().NewLogger("ice")
}

var localAddrsForUnspecified []net.Addr
if udpAddr, ok := params.UDPConn.LocalAddr().(*net.UDPAddr); !ok { //nolint:nestif
var isUnspecified bool
if udpAddr, ok := params.UDPConn.LocalAddr().(*net.UDPAddr); !ok {
params.Logger.Errorf("LocalAddr is not a net.UDPAddr, got %T", params.UDPConn.LocalAddr())
} else if ok && udpAddr.IP.IsUnspecified() {
// For unspecified addresses, the correct behavior is to return errListenUnspecified, but

@JoTurk JoTurk Jun 2, 2026

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.

There is another cache layer in pion/transport that caches the network interfaces https://github.com/pion/transport/blob/1bb98ade0d7759304c0b88bd33914b42bc7f481b/stdnet/net.go#L70-L72 so localInterfaces will just return the same cached interfaces.

maybe we should share the refresh logic with nomination

ice/gather.go

Lines 1402 to 1405 in bd194f6

func (a *Agent) detectNetworkChanges() bool {
// Try to refresh interfaces if using stdnet
if stdNet, ok := a.net.(*stdnet.Net); ok {
if err := stdNet.UpdateInterfaces(); err != nil {
and call updateInterfaces?

@aler9

aler9 commented Jun 2, 2026

Copy link
Copy Markdown
Member Author

@JoTurk i did an assessment on the network change issue some time ago that confirms what you wrote about the two separate cache layers.

As you mentioned there's also a refresh mechanism that is unfortunately placed in the wrong component, which is the agent inside each PeerConnection, while it should be shared among every component.

In my opinion, the right place in which to put the refresh mechanism is inside a shared instance of stdnet.Net / transport.Net, and that's what i did in my overall fix - i didn't contribute it because it's a breaking change.

Anyway, a common step to any solution is to remove the cache layer inside UDPMuxDefault (which is this PR).

@JoTurk JoTurk requested a review from cnderrauber June 2, 2026 10:36

@cnderrauber cnderrauber 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.

Looks good!!

Comment thread udp_mux.go
@aler9 aler9 force-pushed the fix/udp-localaddrs branch 5 times, most recently from 11fd566 to 34702fb Compare June 4, 2026 08:09

@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.

thank you @aler9

UDPMuxDefault was internally caching the list of local IPs, making
connectivity impossible after a network change or a local IP change.
This was also redundant given the fact that IPs and interfaces are
already cached by their provider, which is stdnet.Net / transport.Net.

This patch removes this cache layer, allowing UDPMuxDefault to receive
upstream interface and IP changes, and fixing support for network
changes.
@aler9 aler9 force-pushed the fix/udp-localaddrs branch from 34702fb to 730d8f2 Compare June 4, 2026 16:14
@aler9 aler9 merged commit 72f5001 into pion:main Jun 4, 2026
17 of 18 checks passed
@aler9 aler9 deleted the fix/udp-localaddrs branch June 4, 2026 16:20
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