Skip to content

Commit

Permalink
wait for log producer to really stop inside StopLogProducer func
Browse files Browse the repository at this point in the history
  • Loading branch information
gflarity committed Sep 29, 2023
1 parent eb818e0 commit 044bcc0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 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,13 @@ 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) {

Check failure on line 623 in docker.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, ubuntu-latest) / ./ubuntu-latest/1.20.x

File is not `gofumpt`-ed (gofumpt)
// 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 +708,7 @@ func (c *DockerContainer) StartLogProducer(ctx context.Context) error {
}
}
}
}(c.stopProducer)
}(c.stopProducer, c.producerDone)

return nil
}
Expand All @@ -712,7 +718,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 044bcc0

Please sign in to comment.