From 5a0e56e105f62ea68dbfd1d2c84a6b7ae60d2faa Mon Sep 17 00:00:00 2001 From: Joe Turki Date: Fri, 19 Sep 2025 06:19:21 +0300 Subject: [PATCH] Prefer makezero with a cap --- internal/mux/mux.go | 4 ++-- peerconnection.go | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/mux/mux.go b/internal/mux/mux.go index 94247689..402c2be5 100644 --- a/internal/mux/mux.go +++ b/internal/mux/mux.go @@ -202,14 +202,14 @@ func (m *Mux) handlePendingPackets(endpoint *Endpoint, matchFunc MatchFunc) { m.lock.Lock() defer m.lock.Unlock() - pendingPackets := make([][]byte, len(m.pendingPackets)) + pendingPackets := make([][]byte, 0, len(m.pendingPackets)) for _, buf := range m.pendingPackets { if matchFunc(buf) { if _, err := endpoint.buffer.Write(buf); err != nil { m.log.Warnf("Warning: mux: error writing packet to endpoint from pending queue: %s", err) } } else { - pendingPackets = append(pendingPackets, buf) //nolint:makezero // todo fix + pendingPackets = append(pendingPackets, buf) } } m.pendingPackets = pendingPackets diff --git a/peerconnection.go b/peerconnection.go index 78244965..78a2b0b5 100644 --- a/peerconnection.go +++ b/peerconnection.go @@ -2414,7 +2414,7 @@ func (pc *PeerConnection) close(shouldGracefullyClose bool) error { //nolint:cyc // 2. A Mux stops this chain. It won't close the underlying // Conn if one of the endpoints is closed down. To // continue the chain the Mux has to be closed. - closeErrs := make([]error, 4) + closeErrs := make([]error, 0, 4) doGracefulCloseOps := func() []error { if !shouldGracefullyClose { @@ -2448,10 +2448,10 @@ func (pc *PeerConnection) close(shouldGracefullyClose bool) error { //nolint:cyc // https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #4) pc.mu.Lock() for _, t := range pc.rtpTransceivers { - closeErrs = append(closeErrs, t.Stop()) //nolint:makezero // todo fix + closeErrs = append(closeErrs, t.Stop()) } if nonMediaBandwidthProbe, ok := pc.nonMediaBandwidthProbe.Load().(*RTPReceiver); ok { - closeErrs = append(closeErrs, nonMediaBandwidthProbe.Stop()) //nolint:makezero // todo fix + closeErrs = append(closeErrs, nonMediaBandwidthProbe.Stop()) } pc.mu.Unlock() @@ -2464,28 +2464,28 @@ func (pc *PeerConnection) close(shouldGracefullyClose bool) error { //nolint:cyc // https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #6) if pc.sctpTransport != nil { - closeErrs = append(closeErrs, pc.sctpTransport.Stop()) //nolint:makezero // todo fix + closeErrs = append(closeErrs, pc.sctpTransport.Stop()) } // https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #7) - closeErrs = append(closeErrs, pc.dtlsTransport.Stop()) //nolint:makezero // todo fix + closeErrs = append(closeErrs, pc.dtlsTransport.Stop()) // https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #8, #9, #10) if pc.iceTransport != nil && !shouldGracefullyClose { // we will stop gracefully in doGracefulCloseOps - closeErrs = append(closeErrs, pc.iceTransport.Stop()) //nolint:makezero // todo fix + closeErrs = append(closeErrs, pc.iceTransport.Stop()) } // https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #11) pc.updateConnectionState(pc.ICEConnectionState(), pc.dtlsTransport.State()) - closeErrs = append(closeErrs, doGracefulCloseOps()...) //nolint:makezero // todo fix + closeErrs = append(closeErrs, doGracefulCloseOps()...) pc.statsGetter = nil cleanupStats(pc.statsID) // Interceptor closes at the end to prevent Bind from being called after interceptor is closed - closeErrs = append(closeErrs, pc.api.interceptor.Close()) //nolint:makezero // todo fix + closeErrs = append(closeErrs, pc.api.interceptor.Close()) return util.FlattenErrs(closeErrs) }