make sure components are closed in a specific order (#2065)
This commit is contained in:
+15
-22
@@ -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 {
|
||||
_, 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 {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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) {
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
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
|
||||
|
||||
@@ -63,7 +63,6 @@ type hlsManager struct {
|
||||
}
|
||||
|
||||
func newHLSManager(
|
||||
parentCtx context.Context,
|
||||
address string,
|
||||
encryption bool,
|
||||
serverKey string,
|
||||
@@ -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,
|
||||
|
||||
@@ -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(
|
||||
metrics *metrics,
|
||||
parent pathManagerParent,
|
||||
) *pathManager {
|
||||
ctx, ctxCancel := context.WithCancel(parentCtx)
|
||||
ctx, ctxCancel := context.WithCancel(context.Background())
|
||||
|
||||
pm := &pathManager{
|
||||
externalAuthenticationURL: externalAuthenticationURL,
|
||||
|
||||
@@ -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(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx, ctxCancel := context.WithCancel(parentCtx)
|
||||
ctx, ctxCancel := context.WithCancel(context.Background())
|
||||
|
||||
s := &rtmpServer{
|
||||
readTimeout: readTimeout,
|
||||
|
||||
@@ -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(
|
||||
pathManager *pathManager,
|
||||
parent rtspServerParent,
|
||||
) (*rtspServer, error) {
|
||||
ctx, ctxCancel := context.WithCancel(parentCtx)
|
||||
ctx, ctxCancel := context.WithCancel(context.Background())
|
||||
|
||||
s := &rtspServer{
|
||||
authMethods: authMethods,
|
||||
|
||||
@@ -150,7 +150,6 @@ type webRTCManager struct {
|
||||
}
|
||||
|
||||
func newWebRTCManager(
|
||||
parentCtx context.Context,
|
||||
address string,
|
||||
encryption bool,
|
||||
serverKey string,
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user