Log error on SO_REUSEPORT and continue (#2243)

The underlying system might not support
SO_REUSEPORT, even though it is available in
kernel 3.9+. If there's an error, continue.

Signed-off-by: stuart nelson <stuartnelson3@gmail.com>
This commit is contained in:
stuart nelson 2018-10-28 17:02:58 +01:00 committed by Miek Gieben
parent 7b25d18019
commit dc85f14e5c

View file

@ -8,19 +8,17 @@ import (
"net"
"syscall"
"github.com/coredns/coredns/plugin/pkg/log"
"golang.org/x/sys/unix"
)
const supportsReusePort = true
func reuseportControl(network, address string, c syscall.RawConn) (opErr error) {
err := c.Control(func(fd uintptr) {
opErr = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
func reuseportControl(network, address string, c syscall.RawConn) error {
c.Control(func(fd uintptr) {
if err := unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1); err != nil {
log.Warningf("Failed to set SO_REUSEPORT on socket: %s", err)
}
})
if err != nil {
return err
}
return opErr
return nil
}
func listen(network, addr string) (net.Listener, error) {