Browse Source

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

pull/2098/head
Alessandro Ros 3 years ago committed by GitHub
parent
commit
af23609d47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      internal/core/webrtc_manager.go
  2. 11
      internal/core/webrtc_session.go

2
internal/core/webrtc_manager.go

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

11
internal/core/webrtc_session.go

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

Loading…
Cancel
Save