api: fix crash when calling /v1/webrtcsessions/list just after session creation (#2097)

This commit is contained in:
Alessandro Ros 2023-07-23 18:40:06 +02:00 committed by GitHub
parent 3bb12e2a0a
commit af23609d47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View File

@ -269,7 +269,7 @@ outer:
sx := newWebRTCSession(
m.ctx,
m.readBufferCount,
req.remoteAddr,
req,
&wg,
m.iceHostNAT1To1IPs,
m.iceUDPMux,

View File

@ -113,6 +113,7 @@ type webRTCSessionPathManager interface {
type webRTCSession struct {
readBufferCount int
req webRTCSessionNewReq
wg *sync.WaitGroup
iceHostNAT1To1IPs []string
iceUDPMux ice.UDPMux
@ -125,7 +126,6 @@ type webRTCSession struct {
created time.Time
uuid uuid.UUID
secret uuid.UUID
req webRTCSessionNewReq
answerSent bool
mutex sync.RWMutex
pc *peerConnection
@ -137,7 +137,7 @@ type webRTCSession struct {
func newWebRTCSession(
parentCtx context.Context,
readBufferCount int,
remoteAddr string,
req webRTCSessionNewReq,
wg *sync.WaitGroup,
iceHostNAT1To1IPs []string,
iceUDPMux ice.UDPMux,
@ -149,6 +149,7 @@ func newWebRTCSession(
s := &webRTCSession{
readBufferCount: readBufferCount,
req: req,
wg: wg,
iceHostNAT1To1IPs: iceHostNAT1To1IPs,
iceUDPMux: iceUDPMux,
@ -164,7 +165,7 @@ func newWebRTCSession(
chAddCandidates: make(chan webRTCSessionAddCandidatesReq),
}
s.Log(logger.Info, "created by %s", remoteAddr)
s.Log(logger.Info, "created by %s", req.remoteAddr)
wg.Add(1)
go s.run()
@ -195,8 +196,8 @@ func (s *webRTCSession) run() {
func (s *webRTCSession) runInner() error {
select {
case req := <-s.chNew:
s.req = req
case <-s.chNew:
// do not store the request, we already have it
case <-s.ctx.Done():
return fmt.Errorf("terminated")