diff --git a/fanout.go b/fanout.go index 56608fa..1d7d5e7 100644 --- a/fanout.go +++ b/fanout.go @@ -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++ { diff --git a/setup_test.go b/setup_test.go index 2042bcf..0497e47 100644 --- a/setup_test.go +++ b/setup_test.go @@ -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() {