fix regression of 'sourceOnDemand: no'; fix #49
This commit is contained in:
parent
a5bd05dcfc
commit
4c97c88926
27
path.go
27
path.go
|
@ -66,7 +66,11 @@ func (pa *path) check() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if source, ok := pa.publisher.(*source); ok {
|
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 {
|
hasClients := func() bool {
|
||||||
for c := range pa.p.clients {
|
for c := range pa.p.clients {
|
||||||
if c.pathId == pa.id {
|
if c.pathId == pa.id {
|
||||||
|
@ -75,10 +79,7 @@ func (pa *path) check() {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}()
|
}()
|
||||||
|
if !hasClients {
|
||||||
// stop source if needed
|
|
||||||
if !hasClients &&
|
|
||||||
time.Since(pa.lastRequested) >= 10*time.Second {
|
|
||||||
source.log("stopping since we're not requested anymore")
|
source.log("stopping since we're not requested anymore")
|
||||||
source.state = sourceStateStopped
|
source.state = sourceStateStopped
|
||||||
source.events <- sourceEventApplyState{source.state}
|
source.events <- sourceEventApplyState{source.state}
|
||||||
|
@ -86,7 +87,10 @@ func (pa *path) check() {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} 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 {
|
hasClientReaders := func() bool {
|
||||||
for c := range pa.p.clients {
|
for c := range pa.p.clients {
|
||||||
if c.pathId == pa.id && c != pa.publisher {
|
if c.pathId == pa.id && c != pa.publisher {
|
||||||
|
@ -95,12 +99,8 @@ func (pa *path) check() {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}()
|
}()
|
||||||
|
if !hasClientReaders {
|
||||||
// stop on demand command if needed
|
|
||||||
if !hasClientReaders &&
|
|
||||||
time.Since(pa.lastRequested) >= 10*time.Second {
|
|
||||||
pa.p.log("stopping on demand command since it is not requested anymore")
|
pa.p.log("stopping on demand command since it is not requested anymore")
|
||||||
|
|
||||||
pa.onDemandCmd.Process.Signal(os.Interrupt)
|
pa.onDemandCmd.Process.Signal(os.Interrupt)
|
||||||
pa.onDemandCmd.Wait()
|
pa.onDemandCmd.Wait()
|
||||||
pa.onDemandCmd = nil
|
pa.onDemandCmd = nil
|
||||||
|
@ -115,6 +115,7 @@ func (pa *path) describe(client *client) {
|
||||||
// publisher not found
|
// publisher not found
|
||||||
if pa.publisher == nil {
|
if pa.publisher == nil {
|
||||||
if pa.confp.RunOnDemand != "" {
|
if pa.confp.RunOnDemand != "" {
|
||||||
|
// start on demand command if needed; put the client on hold
|
||||||
if pa.onDemandCmd == nil {
|
if pa.onDemandCmd == nil {
|
||||||
pa.p.log("starting on demand command")
|
pa.p.log("starting on demand command")
|
||||||
|
|
||||||
|
@ -131,12 +132,12 @@ func (pa *path) describe(client *client) {
|
||||||
client.pathId = pa.id
|
client.pathId = pa.id
|
||||||
client.state = clientStateWaitingDescription
|
client.state = clientStateWaitingDescription
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
// no on-demand: reply with 404
|
||||||
client.describeRes <- describeRes{nil, fmt.Errorf("no one is publishing on path '%s'", pa.id)}
|
client.describeRes <- describeRes{nil, fmt.Errorf("no one is publishing on path '%s'", pa.id)}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// publisher was found but is not ready: put the client on hold
|
// publisher was found but is not ready: put the client on hold
|
||||||
if !pa.publisherReady {
|
if !pa.publisherReady {
|
||||||
|
|
Loading…
Reference in New Issue