File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ type DockerContainer struct {
67
67
consumers []LogConsumer
68
68
raw * types.ContainerJSON
69
69
stopProducer chan bool
70
+ producerDone chan bool
70
71
logger Logging
71
72
lifecycleHooks []ContainerLifecycleHooks
72
73
}
@@ -616,8 +617,12 @@ func (c *DockerContainer) StartLogProducer(ctx context.Context) error {
616
617
}
617
618
618
619
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 )
619
625
620
- go func (stop <- chan bool ) {
621
626
since := ""
622
627
// if the socket is closed we will make additional logs request with updated Since timestamp
623
628
BEGIN:
@@ -702,7 +707,7 @@ func (c *DockerContainer) StartLogProducer(ctx context.Context) error {
702
707
}
703
708
}
704
709
}
705
- }(c .stopProducer )
710
+ }(c .stopProducer , c . producerDone )
706
711
707
712
return nil
708
713
}
@@ -712,7 +717,10 @@ func (c *DockerContainer) StartLogProducer(ctx context.Context) error {
712
717
func (c * DockerContainer ) StopLogProducer () error {
713
718
if c .stopProducer != nil {
714
719
c .stopProducer <- true
720
+ // block until the producer is actually done in order to avoid strange races
721
+ <- c .producerDone
715
722
c .stopProducer = nil
723
+ c .producerDone = nil
716
724
}
717
725
return nil
718
726
}
You can’t perform that action at this time.
0 commit comments