From 4c97c889261a09ed14f460508a7bcea3411e4622 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Fri, 31 Jul 2020 17:46:40 +0200 Subject: [PATCH] fix regression of 'sourceOnDemand: no'; fix #49 --- path.go | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/path.go b/path.go index 9e2d277e..db3db648 100644 --- a/path.go +++ b/path.go @@ -66,7 +66,11 @@ func (pa *path) check() { } if source, ok := pa.publisher.(*source); ok { - if source.state == sourceStateRunning { + // stop on demand source if needed + if pa.confp.SourceOnDemand && + source.state == sourceStateRunning && + time.Since(pa.lastRequested) >= 10*time.Second { + hasClients := func() bool { for c := range pa.p.clients { if c.pathId == pa.id { @@ -75,10 +79,7 @@ func (pa *path) check() { } return false }() - - // stop source if needed - if !hasClients && - time.Since(pa.lastRequested) >= 10*time.Second { + if !hasClients { source.log("stopping since we're not requested anymore") source.state = sourceStateStopped source.events <- sourceEventApplyState{source.state} @@ -86,7 +87,10 @@ func (pa *path) check() { } } else { - if pa.onDemandCmd != nil { + // stop on demand command if needed + if pa.onDemandCmd != nil && + time.Since(pa.lastRequested) >= 10*time.Second { + hasClientReaders := func() bool { for c := range pa.p.clients { if c.pathId == pa.id && c != pa.publisher { @@ -95,12 +99,8 @@ func (pa *path) check() { } return false }() - - // stop on demand command if needed - if !hasClientReaders && - time.Since(pa.lastRequested) >= 10*time.Second { + if !hasClientReaders { pa.p.log("stopping on demand command since it is not requested anymore") - pa.onDemandCmd.Process.Signal(os.Interrupt) pa.onDemandCmd.Wait() pa.onDemandCmd = nil @@ -115,6 +115,7 @@ func (pa *path) describe(client *client) { // publisher not found if pa.publisher == nil { if pa.confp.RunOnDemand != "" { + // start on demand command if needed; put the client on hold if pa.onDemandCmd == nil { pa.p.log("starting on demand command") @@ -131,11 +132,11 @@ func (pa *path) describe(client *client) { client.pathId = pa.id client.state = clientStateWaitingDescription return - - } else { - client.describeRes <- describeRes{nil, fmt.Errorf("no one is publishing on path '%s'", pa.id)} - return } + + // no on-demand: reply with 404 + client.describeRes <- describeRes{nil, fmt.Errorf("no one is publishing on path '%s'", pa.id)} + return } // publisher was found but is not ready: put the client on hold