Skip to content

fix: End new target loop on closed channel #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions stern/docker_stern.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ func RunDocker(ctx context.Context, client *dockerclient.Client, config *DockerC
}

var numRequests atomic.Int64
for {
target := <-added
for target := range added {
numRequests.Add(1)
if numRequests.Load() > int64(config.MaxLogRequests) {
return fmt.Errorf("tailfin reached the maximum number of log requests (%d),"+
Expand All @@ -138,4 +137,5 @@ func RunDocker(ctx context.Context, client *dockerclient.Client, config *DockerC
numRequests.Add(-1)
}()
}
return nil
}
4 changes: 3 additions & 1 deletion stern/docker_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package stern

import (
"context"
"fmt"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/events"
Expand Down Expand Up @@ -60,7 +61,8 @@ func WatchDockers(ctx context.Context, config *DockerConfig, filter *dockerTarge
case <-ctx.Done():
close(added)
return
case <-errc:
case err := <-errc:
fmt.Fprintf(config.ErrOut, "dockerd error: %v\n", err)
close(added)
return
}
Expand Down