From f8b3e6a0c790aa02f9758a4e9fb720884e81f891 Mon Sep 17 00:00:00 2001 From: cnderrauber Date: Wed, 24 Apr 2024 16:50:23 +0800 Subject: [PATCH] Replace pool with bytes in readLoop Replace pool with bytes in readLoop --- datachannel.go | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/datachannel.go b/datachannel.go index a846eb58e3d..b3dfdad4e10 100644 --- a/datachannel.go +++ b/datachannel.go @@ -349,18 +349,11 @@ func (d *DataChannel) onError(err error) { } } -// See https://github.com/pion/webrtc/issues/1516 -// nolint:gochecknoglobals -var rlBufPool = sync.Pool{New: func() interface{} { - return make([]byte, dataChannelBufferSize) -}} - func (d *DataChannel) readLoop() { + buffer := make([]byte, dataChannelBufferSize) for { - buffer := rlBufPool.Get().([]byte) //nolint:forcetypeassert n, isString, err := d.dataChannel.ReadDataChannel(buffer) if err != nil { - rlBufPool.Put(buffer) // nolint:staticcheck d.setReadyState(DataChannelStateClosed) if !errors.Is(err, io.EOF) { d.onError(err) @@ -371,8 +364,6 @@ func (d *DataChannel) readLoop() { m := DataChannelMessage{Data: make([]byte, n), IsString: isString} copy(m.Data, buffer[:n]) - // The 'staticcheck' pragma is a false positive on the part of the CI linter. - rlBufPool.Put(buffer) // nolint:staticcheck // NB: Why was DataChannelMessage not passed as a pointer value? d.onMessage(m) // nolint:staticcheck