mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
Failed startup was not flagged (#118)
The error propagation from srv.ListenAndServe did not work as intended, simplified it a bit and added a test for it.
This commit is contained in:
@@ -163,8 +163,8 @@ func (s *Server) Serve(ln ListenerFile) error {
|
|||||||
// ListenAndServe starts the server with a new listener. It blocks until the server stops.
|
// ListenAndServe starts the server with a new listener. It blocks until the server stops.
|
||||||
func (s *Server) ListenAndServe() error {
|
func (s *Server) ListenAndServe() error {
|
||||||
err := s.setup()
|
err := s.setup()
|
||||||
|
defer close(s.startChan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
close(s.startChan)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,8 +187,6 @@ func (s *Server) ListenAndServe() error {
|
|||||||
go func() {
|
go func() {
|
||||||
s.server[0].ActivateAndServe()
|
s.server[0].ActivateAndServe()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
close(s.startChan) // unblock anyone waiting for this to start listening
|
|
||||||
return s.server[1].ActivateAndServe()
|
return s.server[1].ActivateAndServe()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
21
test/fail_start_test.go
Normal file
21
test/fail_start_test.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/miekg/coredns/core"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Bind to low port should fail.
|
||||||
|
func TestFailStartServer(t *testing.T) {
|
||||||
|
corefile := `.:53 {
|
||||||
|
chaos CoreDNS-001 miek@miek.nl
|
||||||
|
}
|
||||||
|
`
|
||||||
|
srv, _ := core.TestServer(t, corefile)
|
||||||
|
err := srv.ListenAndServe()
|
||||||
|
if err == nil {
|
||||||
|
srv.Stop()
|
||||||
|
t.Fatalf("Low port startup should fail")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,7 +34,7 @@ func Server(t *testing.T, corefile string) (*server.Server, string, string, erro
|
|||||||
}
|
}
|
||||||
go srv.ListenAndServe()
|
go srv.ListenAndServe()
|
||||||
|
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second) // yeah... I regret nothing
|
||||||
tcp, udp := srv.LocalAddr()
|
tcp, udp := srv.LocalAddr()
|
||||||
return srv, tcp.String(), udp.String(), nil
|
return srv, tcp.String(), udp.String(), nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user