Skip to content

Commit

Permalink
Merge pull request #33 from denis-tingaikin/fix-issue-14
Browse files Browse the repository at this point in the history
fix: properly close workerchannel
  • Loading branch information
edwarnicke authored Jan 20, 2021
2 parents 84902c6 + b6e05d9 commit 241bb94
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
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

0 comments on commit 241bb94

Please sign in to comment.