Browse Source

make sure components are closed in a specific order (#2065)

pull/2071/head
Alessandro Ros 3 years ago committed by GitHub
parent
commit
ffa012ab3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 37
      internal/core/core.go
  2. 3
      internal/core/hls_manager.go
  3. 3
      internal/core/path_manager.go
  4. 3
      internal/core/rtmp_server.go
  5. 3
      internal/core/rtsp_server.go
  6. 3
      internal/core/webrtc_manager.go

37
internal/core/core.go

@ -241,7 +241,6 @@ func (p *Core) createResources(initial bool) error { @@ -241,7 +241,6 @@ func (p *Core) createResources(initial bool) error {
if p.pathManager == nil {
p.pathManager = newPathManager(
p.ctx,
p.conf.ExternalAuthenticationURL,
p.conf.RTSPAddress,
p.conf.AuthMethods,
@ -263,7 +262,6 @@ func (p *Core) createResources(initial bool) error { @@ -263,7 +262,6 @@ func (p *Core) createResources(initial bool) error {
_, useUDP := p.conf.Protocols[conf.Protocol(gortsplib.TransportUDP)]
_, useMulticast := p.conf.Protocols[conf.Protocol(gortsplib.TransportUDPMulticast)]
p.rtspServer, err = newRTSPServer(
p.ctx,
p.conf.RTSPAddress,
p.conf.AuthMethods,
p.conf.ReadTimeout,
@ -299,7 +297,6 @@ func (p *Core) createResources(initial bool) error { @@ -299,7 +297,6 @@ func (p *Core) createResources(initial bool) error {
p.conf.Encryption == conf.EncryptionOptional) {
if p.rtspsServer == nil {
p.rtspsServer, err = newRTSPServer(
p.ctx,
p.conf.RTSPSAddress,
p.conf.AuthMethods,
p.conf.ReadTimeout,
@ -335,7 +332,6 @@ func (p *Core) createResources(initial bool) error { @@ -335,7 +332,6 @@ func (p *Core) createResources(initial bool) error {
p.conf.RTMPEncryption == conf.EncryptionOptional) {
if p.rtmpServer == nil {
p.rtmpServer, err = newRTMPServer(
p.ctx,
p.conf.RTMPAddress,
p.conf.ReadTimeout,
p.conf.WriteTimeout,
@ -362,7 +358,6 @@ func (p *Core) createResources(initial bool) error { @@ -362,7 +358,6 @@ func (p *Core) createResources(initial bool) error {
p.conf.RTMPEncryption == conf.EncryptionOptional) {
if p.rtmpsServer == nil {
p.rtmpsServer, err = newRTMPServer(
p.ctx,
p.conf.RTMPSAddress,
p.conf.ReadTimeout,
p.conf.WriteTimeout,
@ -387,7 +382,6 @@ func (p *Core) createResources(initial bool) error { @@ -387,7 +382,6 @@ func (p *Core) createResources(initial bool) error {
if !p.conf.HLSDisable {
if p.hlsManager == nil {
p.hlsManager, err = newHLSManager(
p.ctx,
p.conf.HLSAddress,
p.conf.HLSEncryption,
p.conf.HLSServerKey,
@ -417,7 +411,6 @@ func (p *Core) createResources(initial bool) error { @@ -417,7 +411,6 @@ func (p *Core) createResources(initial bool) error {
if !p.conf.WebRTCDisable {
if p.webRTCManager == nil {
p.webRTCManager, err = newWebRTCManager(
p.ctx,
p.conf.WebRTCAddress,
p.conf.WebRTCEncryption,
p.conf.WebRTCServerKey,
@ -628,21 +621,6 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) { @@ -628,21 +621,6 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) {
}
}
if closeRTSPSServer && p.rtspsServer != nil {
p.rtspsServer.close()
p.rtspsServer = nil
}
if closeRTSPServer && p.rtspServer != nil {
p.rtspServer.close()
p.rtspServer = nil
}
if closePathManager && p.pathManager != nil {
p.pathManager.close()
p.pathManager = nil
}
if closeWebRTCManager && p.webRTCManager != nil {
p.webRTCManager.close()
p.webRTCManager = nil
@ -663,6 +641,21 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) { @@ -663,6 +641,21 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) {
p.rtmpServer = nil
}
if closeRTSPSServer && p.rtspsServer != nil {
p.rtspsServer.close()
p.rtspsServer = nil
}
if closeRTSPServer && p.rtspServer != nil {
p.rtspServer.close()
p.rtspServer = nil
}
if closePathManager && p.pathManager != nil {
p.pathManager.close()
p.pathManager = nil
}
if closePPROF && p.pprof != nil {
p.pprof.close()
p.pprof = nil

3
internal/core/hls_manager.go

@ -63,7 +63,6 @@ type hlsManager struct { @@ -63,7 +63,6 @@ type hlsManager struct {
}
func newHLSManager(
parentCtx context.Context,
address string,
encryption bool,
serverKey string,
@ -84,7 +83,7 @@ func newHLSManager( @@ -84,7 +83,7 @@ func newHLSManager(
metrics *metrics,
parent hlsManagerParent,
) (*hlsManager, error) {
ctx, ctxCancel := context.WithCancel(parentCtx)
ctx, ctxCancel := context.WithCancel(context.Background())
m := &hlsManager{
externalAuthenticationURL: externalAuthenticationURL,

3
internal/core/path_manager.go

@ -74,7 +74,6 @@ type pathManager struct { @@ -74,7 +74,6 @@ type pathManager struct {
}
func newPathManager(
parentCtx context.Context,
externalAuthenticationURL string,
rtspAddress string,
authMethods conf.AuthMethods,
@ -87,7 +86,7 @@ func newPathManager( @@ -87,7 +86,7 @@ func newPathManager(
metrics *metrics,
parent pathManagerParent,
) *pathManager {
ctx, ctxCancel := context.WithCancel(parentCtx)
ctx, ctxCancel := context.WithCancel(context.Background())
pm := &pathManager{
externalAuthenticationURL: externalAuthenticationURL,

3
internal/core/rtmp_server.go

@ -74,7 +74,6 @@ type rtmpServer struct { @@ -74,7 +74,6 @@ type rtmpServer struct {
}
func newRTMPServer(
parentCtx context.Context,
address string,
readTimeout conf.StringDuration,
writeTimeout conf.StringDuration,
@ -107,7 +106,7 @@ func newRTMPServer( @@ -107,7 +106,7 @@ func newRTMPServer(
return nil, err
}
ctx, ctxCancel := context.WithCancel(parentCtx)
ctx, ctxCancel := context.WithCancel(context.Background())
s := &rtmpServer{
readTimeout: readTimeout,

3
internal/core/rtsp_server.go

@ -63,7 +63,6 @@ type rtspServer struct { @@ -63,7 +63,6 @@ type rtspServer struct {
}
func newRTSPServer(
parentCtx context.Context,
address string,
authMethods []headers.AuthMethod,
readTimeout conf.StringDuration,
@ -88,7 +87,7 @@ func newRTSPServer( @@ -88,7 +87,7 @@ func newRTSPServer(
pathManager *pathManager,
parent rtspServerParent,
) (*rtspServer, error) {
ctx, ctxCancel := context.WithCancel(parentCtx)
ctx, ctxCancel := context.WithCancel(context.Background())
s := &rtspServer{
authMethods: authMethods,

3
internal/core/webrtc_manager.go

@ -150,7 +150,6 @@ type webRTCManager struct { @@ -150,7 +150,6 @@ type webRTCManager struct {
}
func newWebRTCManager(
parentCtx context.Context,
address string,
encryption bool,
serverKey string,
@ -167,7 +166,7 @@ func newWebRTCManager( @@ -167,7 +166,7 @@ func newWebRTCManager(
iceUDPMuxAddress string,
iceTCPMuxAddress string,
) (*webRTCManager, error) {
ctx, ctxCancel := context.WithCancel(parentCtx)
ctx, ctxCancel := context.WithCancel(context.Background())
m := &webRTCManager{
allowOrigin: allowOrigin,

Loading…
Cancel
Save