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

3
internal/core/hls_manager.go

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

3
internal/core/path_manager.go

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

3
internal/core/rtmp_server.go

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

3
internal/core/rtsp_server.go

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

3
internal/core/webrtc_manager.go

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

Loading…
Cancel
Save