Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions error_conn.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT

package ice

import (
"net"
"time"
)

// ErrorConn for net.PacketConn when the value is nil.
type ErrorConn struct{}

func (e *ErrorConn) ReadFrom([]byte) (n int, addr net.Addr, err error) {
var dummyAddr *net.IPAddr

return 0, dummyAddr, ErrPacketConnNil
}
func (e *ErrorConn) WriteTo([]byte, net.Addr) (n int, err error) { return 0, ErrPacketConnNil }
func (e *ErrorConn) Close() error { return ErrPacketConnNil }
func (e *ErrorConn) LocalAddr() net.Addr {
var dummyAddr *net.IPAddr

return dummyAddr
}
func (e *ErrorConn) SetDeadline(time.Time) error { return ErrPacketConnNil }
func (e *ErrorConn) SetReadDeadline(time.Time) error { return ErrPacketConnNil }
func (e *ErrorConn) SetWriteDeadline(time.Time) error { return ErrPacketConnNil }
3 changes: 3 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ var (
// ErrAgentOptionNotUpdatable indicates an option cannot be updated after construction.
ErrAgentOptionNotUpdatable = errors.New("option can only be set during agent construction")

// ErrPacketConnNil indicates an net.PacketConn value was nil.
ErrPacketConnNil = errors.New("net.PacketConn is nil")

errAttributeTooShortICECandidate = errors.New("attribute not long enough to be ICE candidate")
errClosingConnection = errors.New("failed to close connection")
errConnectionAddrAlreadyExist = errors.New("connection with same remote address already exists")
Expand Down
6 changes: 5 additions & 1 deletion udp_mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ func NewUDPMuxDefault(params UDPMuxParams) *UDPMuxDefault { //nolint:cyclop
}

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.

params.Logger.Errorf("UDPConn is nil")
params.UDPConn = &ErrorConn{}
} else if udpAddr, ok := params.UDPConn.LocalAddr().(*net.UDPAddr); !ok { //nolint:nestif
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
Expand Down
Loading