Skip to content

Commit

Permalink
wait for log producer to really stop inside StopLogProducer func (#1701)
Browse files Browse the repository at this point in the history
  • Loading branch information
gflarity authored Oct 24, 2023
1 parent c733f34 commit d43fae3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type DockerContainer struct {
consumers []LogConsumer
raw *types.ContainerJSON
stopProducer chan bool
producerDone chan bool
logger Logging
lifecycleHooks []ContainerLifecycleHooks
}
Expand Down Expand Up @@ -616,8 +617,12 @@ func (c *DockerContainer) StartLogProducer(ctx context.Context) error {
}

c.stopProducer = make(chan bool)
c.producerDone = make(chan bool)

go func(stop <-chan bool, done chan<- bool) {
// signal the producer is done once go routine exits, this prevents race conditions around start/stop
defer close(done)

go func(stop <-chan bool) {
since := ""
// if the socket is closed we will make additional logs request with updated Since timestamp
BEGIN:
Expand Down Expand Up @@ -702,7 +707,7 @@ func (c *DockerContainer) StartLogProducer(ctx context.Context) error {
}
}
}
}(c.stopProducer)
}(c.stopProducer, c.producerDone)

return nil
}
Expand All @@ -712,7 +717,10 @@ func (c *DockerContainer) StartLogProducer(ctx context.Context) error {
func (c *DockerContainer) StopLogProducer() error {
if c.stopProducer != nil {
c.stopProducer <- true
// block until the producer is actually done in order to avoid strange races
<-c.producerDone
c.stopProducer = nil
c.producerDone = nil
}
return nil
}
Expand Down

0 comments on commit d43fae3

Please sign in to comment.