client: fix panic when writing packets after connection error (#681)

* Fix writer nullpointer panic on network reconnect

* add additional code and tests

---------

Co-authored-by: aler9 <46489434+aler9@users.noreply.github.com>
This commit is contained in:
Sijmen
2025-01-18 19:40:47 +01:00
committed by GitHub
parent 6240aa2847
commit b2cfa93d13
5 changed files with 44 additions and 23 deletions

24
async_processor_test.go Normal file
View File

@@ -0,0 +1,24 @@
package gortsplib
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func TestAsyncProcessorStopAfterError(t *testing.T) {
p := &asyncProcessor{bufferSize: 8}
p.initialize()
p.push(func() error {
return fmt.Errorf("ok")
})
p.start()
<-p.stopped
require.EqualError(t, p.stopError, "ok")
p.stop()
}