detect UDP buffer size w/o using original conn.
if we get FD on the mux connection, the connection will be set to blocking mode and then hang when stopping
@@ -89,20 +89,15 @@ func NewWebRTCConfig(conf *config.RTCConfig, externalIP string) (*WebRTCConfig,
UDPConn: udpMuxConn,
})
s.SetICEUDPMux(udpMux)
-
- fd, err := udpMuxConn.File()
- if err == nil {
- value, err := syscall.GetsockoptInt(int(fd.Fd()), syscall.SOL_SOCKET, syscall.SO_RCVBUF)
+ val, err := checkUDPReadBuffer()
if err == nil {
- if value < minUDPBufferSize {
+ if val < minUDPBufferSize {
logger.Warnw("UDP receive buffer is too small for a production set-up", nil,
- "current", value,
+ "current", val,
"suggested", minUDPBufferSize)
} else {
- logger.Debugw("UDP receive buffer size", "current", value)
- }
+ logger.Debugw("UDP receive buffer size", "current", val)
}
- _ = fd.Close()
}
} else if conf.ICEPortRangeStart != 0 && conf.ICEPortRangeEnd != 0 {
if err := s.SetEphemeralUDPPortRange(uint16(conf.ICEPortRangeStart), uint16(conf.ICEPortRangeEnd)); err != nil {
@@ -145,3 +140,19 @@ func NewWebRTCConfig(conf *config.RTCConfig, externalIP string) (*WebRTCConfig,
TCPMuxListener: tcpListener,
}, nil
}
+
+func checkUDPReadBuffer() (int, error) {
+ conn, err := net.ListenUDP("udp4", nil)
+ if err != nil {
+ return 0, err
+ }
+ defer func() { _ = conn.Close() }()
+ _ = conn.SetReadBuffer(minUDPBufferSize)
+ fd, err := conn.File()
+ if err != nil {
+ return 0, nil
+ }
+ defer func() { _ = fd.Close() }()
+
+ return syscall.GetsockoptInt(int(fd.Fd()), syscall.SOL_SOCKET, syscall.SO_RCVBUF)
+}
