Skip to content

Commit d43fae3

Browse files
authored
wait for log producer to really stop inside StopLogProducer func (#1701)
1 parent c733f34 commit d43fae3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

docker.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type DockerContainer struct {
6767
consumers []LogConsumer
6868
raw *types.ContainerJSON
6969
stopProducer chan bool
70+
producerDone chan bool
7071
logger Logging
7172
lifecycleHooks []ContainerLifecycleHooks
7273
}
@@ -616,8 +617,12 @@ func (c *DockerContainer) StartLogProducer(ctx context.Context) error {
616617
}
617618

618619
c.stopProducer = make(chan bool)
620+
c.producerDone = make(chan bool)
621+
622+
go func(stop <-chan bool, done chan<- bool) {
623+
// signal the producer is done once go routine exits, this prevents race conditions around start/stop
624+
defer close(done)
619625

620-
go func(stop <-chan bool) {
621626
since := ""
622627
// if the socket is closed we will make additional logs request with updated Since timestamp
623628
BEGIN:
@@ -702,7 +707,7 @@ func (c *DockerContainer) StartLogProducer(ctx context.Context) error {
702707
}
703708
}
704709
}
705-
}(c.stopProducer)
710+
}(c.stopProducer, c.producerDone)
706711

707712
return nil
708713
}
@@ -712,7 +717,10 @@ func (c *DockerContainer) StartLogProducer(ctx context.Context) error {
712717
func (c *DockerContainer) StopLogProducer() error {
713718
if c.stopProducer != nil {
714719
c.stopProducer <- true
720+
// block until the producer is actually done in order to avoid strange races
721+
<-c.producerDone
715722
c.stopProducer = nil
723+
c.producerDone = nil
716724
}
717725
return nil
718726
}

0 commit comments

Comments
 (0)