Skip to content

Commit 044bcc0

Browse files
committed
wait for log producer to really stop inside StopLogProducer func
1 parent eb818e0 commit 044bcc0

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

docker.go

Lines changed: 11 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,13 @@ 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+
624+
// signal the producer is done once go routine exits, this prevents race conditions around start/stop
625+
defer close(done)
619626

620-
go func(stop <-chan bool) {
621627
since := ""
622628
// if the socket is closed we will make additional logs request with updated Since timestamp
623629
BEGIN:
@@ -702,7 +708,7 @@ func (c *DockerContainer) StartLogProducer(ctx context.Context) error {
702708
}
703709
}
704710
}
705-
}(c.stopProducer)
711+
}(c.stopProducer, c.producerDone)
706712

707713
return nil
708714
}
@@ -712,7 +718,10 @@ func (c *DockerContainer) StartLogProducer(ctx context.Context) error {
712718
func (c *DockerContainer) StopLogProducer() error {
713719
if c.stopProducer != nil {
714720
c.stopProducer <- true
721+
// block until the producer is actually done in order to avoid strange races
722+
<-c.producerDone
715723
c.stopProducer = nil
724+
c.producerDone = nil
716725
}
717726
return nil
718727
}

0 commit comments

Comments
 (0)