use pkg/reuseport in rest plugins (#3492)

Automatically submitted.
This commit is contained in:
Zou Nengren 2019-12-06 18:55:40 +08:00 committed by corbot[bot]
parent af1fe4172a
commit 13fca02316
3 changed files with 11 additions and 6 deletions

View file

@ -6,6 +6,8 @@ import (
"testing"
"time"
"github.com/coredns/coredns/plugin/pkg/reuseport"
tap "github.com/dnstap/golang-dnstap"
fs "github.com/farsightsec/golang-framestream"
)
@ -55,7 +57,7 @@ func TestTransport(t *testing.T) {
for _, param := range transport {
// Start TCP listener
l, err := net.Listen(param[0], param[1])
l, err := reuseport.Listen(param[0], param[1])
if err != nil {
t.Fatalf("Cannot start listener: %s", err)
}
@ -82,7 +84,7 @@ func TestRace(t *testing.T) {
count := 10
// Start TCP listener
l, err := net.Listen("tcp", endpointTCP)
l, err := reuseport.Listen("tcp", endpointTCP)
if err != nil {
t.Fatalf("Cannot start listener: %s", err)
}
@ -115,7 +117,7 @@ func TestReconnect(t *testing.T) {
count := 5
// Start TCP listener
l, err := net.Listen("tcp", endpointTCP)
l, err := reuseport.Listen("tcp", endpointTCP)
if err != nil {
t.Fatalf("Cannot start listener: %s", err)
}
@ -141,7 +143,7 @@ func TestReconnect(t *testing.T) {
l.Close()
// And start TCP listener again on the same port
l, err = net.Listen("tcp", addr)
l, err = reuseport.Listen("tcp", addr)
if err != nil {
t.Fatalf("Cannot start listener: %s", err)
}

View file

@ -10,6 +10,7 @@ import (
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics/vars"
"github.com/coredns/coredns/plugin/pkg/reuseport"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
@ -95,7 +96,7 @@ func (m *Metrics) ZoneNames() []string {
// OnStartup sets up the metrics on startup.
func (m *Metrics) OnStartup() error {
ln, err := net.Listen("tcp", m.Addr)
ln, err := reuseport.Listen("tcp", m.Addr)
if err != nil {
log.Errorf("Failed to start metrics handler: %s", err)
return err

View file

@ -3,6 +3,8 @@ package dnstest
import (
"net"
"github.com/coredns/coredns/plugin/pkg/reuseport"
"github.com/miekg/dns"
)
@ -27,7 +29,7 @@ func NewServer(f dns.HandlerFunc) *Server {
s2 := &dns.Server{} // tcp
for i := 0; i < 5; i++ { // 5 attempts
s2.Listener, _ = net.Listen("tcp", ":0")
s2.Listener, _ = reuseport.Listen("tcp", ":0")
if s2.Listener == nil {
continue
}