File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-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,13 @@ 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
+
624
+ // signal the producer is done once go routine exits, this prevents race conditions around start/stop
625
+ defer close (done )
619
626
620
- go func (stop <- chan bool ) {
621
627
since := ""
622
628
// if the socket is closed we will make additional logs request with updated Since timestamp
623
629
BEGIN:
@@ -702,7 +708,7 @@ func (c *DockerContainer) StartLogProducer(ctx context.Context) error {
702
708
}
703
709
}
704
710
}
705
- }(c .stopProducer )
711
+ }(c .stopProducer , c . producerDone )
706
712
707
713
return nil
708
714
}
@@ -712,7 +718,10 @@ func (c *DockerContainer) StartLogProducer(ctx context.Context) error {
712
718
func (c * DockerContainer ) StopLogProducer () error {
713
719
if c .stopProducer != nil {
714
720
c .stopProducer <- true
721
+ // block until the producer is actually done in order to avoid strange races
722
+ <- c .producerDone
715
723
c .stopProducer = nil
724
+ c .producerDone = nil
716
725
}
717
726
return nil
718
727
}
You can’t perform that action at this time.
0 commit comments