Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Commit

Permalink
cli: don't halt on "protocol not supported" error (fixes #32)
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed May 6, 2019
1 parent 7b7eaa3 commit f799d9b
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions internal/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"net"
"net/http"
"net/http/pprof"
"os"
"strings"
"sync"
"syscall"

"github.com/libp2p/go-reuseport"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -303,9 +305,10 @@ func getListeners(v *viper.Viper, l *zap.Logger) []listener {
}
l.Warn("using", zap.Stringer("a", a))
toListen = append(toListen, listener{
adrr: strings.Replace(normalized, "0.0.0.0", a.IP.String(), -1),
net: "udp",
u: u,
fromAny: true,
adrr: strings.Replace(normalized, "0.0.0.0", a.IP.String(), -1),
net: "udp",
u: u,
})
}
} else {
Expand All @@ -320,6 +323,25 @@ func getListeners(v *viper.Viper, l *zap.Logger) []listener {
return toListen
}

func protocolNotSupported(err error) bool {
switch err := err.(type) {
case syscall.Errno:
switch err {
case syscall.EPROTONOSUPPORT, syscall.ENOPROTOOPT:
return true
}
case *os.SyscallError:
switch err := err.Err.(type) {
case syscall.Errno:
switch err {
case syscall.EPROTONOSUPPORT, syscall.ENOPROTOOPT:
return true
}
}
}
return false
}

func getRoot(v *viper.Viper) *cobra.Command {
cmd := &cobra.Command{
Use: "gortcd",
Expand All @@ -335,10 +357,16 @@ func getRoot(v *viper.Viper) *cobra.Command {
for _, ln := range listeners {
go func() {
defer wg.Done()
l.Info("gortc/gortcd listening", zap.String("addr", ln.adrr),
zap.String("network", "udp"))
lg := l.With(zap.String("addr", ln.adrr), zap.String("network", "udp"))
lg.Info("gortc/gortcd listening")
if err := ListenUDPAndServe(ln.net, ln.adrr, ln.u); err != nil {
l.Fatal("failed to listen", zap.Error(err))
if ln.fromAny && protocolNotSupported(err) {
// See https://github.com/gortc/gortcd/issues/32
// Should be ok to make it non configurable.
lg.Warn("failed to listen", zap.Error(err))
} else {
lg.Fatal("failed to listen", zap.Error(err))
}
}
}()
}
Expand All @@ -362,7 +390,8 @@ func getRoot(v *viper.Viper) *cobra.Command {
}

type listener struct {
net string
adrr string
u *server.Updater
net string
adrr string
u *server.Updater
fromAny bool // as part of 0.0.0.0
}

0 comments on commit f799d9b

Please sign in to comment.