Skip to content

Commit

Permalink
Fix memory leak triggered when container discovery process is in erro…
Browse files Browse the repository at this point in the history
…r loop (#142)
  • Loading branch information
iogakos authored Jul 11, 2023
1 parent 860963e commit d0d1aff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
23 changes: 12 additions & 11 deletions internal/pkg/watch/docker_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,24 @@ func (w *ContainerWatch) repairEventStream(ctx context.Context) (
return nil, nil, fmt.Errorf("got nil container or container with empty names, without an error")
}

containerName := container.Names[0]
reader, err := w.DockerLogsReaderFunc(containerName)
if err != nil {
return nil, nil, err
}
defer reader.Close()

if err := w.blockchain.ReconfigureByDockerContainer(container, reader); err != nil {
return nil, nil, err
}

filter := filters.NewArgs()
filter.Add("type", "container")
filter.Add("event", "start")
filter.Add("event", "stop")
filter.Add("event", "kill")
filter.Add("event", "die")

containerName := container.Names[0]
filter.Add("container", containerName)

options := dt.EventsOptions{Filters: filter}
Expand All @@ -141,16 +151,6 @@ func (w *ContainerWatch) repairEventStream(ctx context.Context) (

zap.S().Debugw("subscribed to docker event stream", "filter", filter)

reader, err := w.DockerLogsReaderFunc(containerName)
if err != nil {
return nil, nil, err
}
defer reader.Close()

if err := w.blockchain.ReconfigureByDockerContainer(container, reader); err != nil {
return nil, nil, err
}

return msgchan, errchan, nil
}

Expand Down Expand Up @@ -215,6 +215,7 @@ func (w *ContainerWatch) StartUnsafe() {
w.emitAgentNodeEvent(model.AgentNodeDownName)

resetTimers()
cancel()

continue
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/watch/docker_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
const (
maxLineBytes = uint32(1024 * 1024)

defaultRetryIntv = 3 * time.Second
defaultRetryIntv = 10 * time.Second
defaultPendingStartInterval = time.Second
)

Expand Down

0 comments on commit d0d1aff

Please sign in to comment.