Skip to content
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

fix: properly close workerchannel #33

Merged
merged 1 commit into from
Jan 20, 2021
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
9 changes: 7 additions & 2 deletions fanout.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,17 @@ func (f *Fanout) ServeDNS(ctx context.Context, w dns.ResponseWriter, m *dns.Msg)
defer cancel()
clientCount := len(f.clients)
workerChannel := make(chan Client, f.workerCount)
defer close(workerChannel)
responseCh := make(chan *response, clientCount)
go func() {
defer close(workerChannel)
for i := 0; i < clientCount; i++ {
client := f.clients[i]
workerChannel <- client
select {
case <-timeoutContext.Done():
return
case workerChannel <- client:
continue
}
}
}()
for i := 0; i < f.workerCount; i++ {
Expand Down
2 changes: 1 addition & 1 deletion setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestSetupResolvconf(t *testing.T) {
const resolv = "resolv.conf"
if err := ioutil.WriteFile(resolv,
[]byte(`nameserver 10.10.255.252
nameserver 10.10.255.253`), 0666); err != nil {
nameserver 10.10.255.253`), 0600); err != nil {
t.Fatalf("Failed to write resolv.conf file: %s", err)
}
defer func() {
Expand Down