Improve error handling for listening

Will help with #290.
This commit is contained in:
Matt Joiner 2018-11-19 20:35:21 +11:00
parent 1dc406c81c
commit 7f133b677c
1 changed files with 3 additions and 2 deletions

View File

@ -10,6 +10,7 @@ import (
"github.com/anacrolix/missinggo"
"github.com/anacrolix/missinggo/perf"
"github.com/pkg/errors"
"golang.org/x/net/proxy"
)
@ -123,7 +124,7 @@ func listenAllRetry(nahs []networkAndHost, port int, proxyURL string, f firewall
portStr := strconv.FormatInt(int64(port), 10)
ss[0], err = listen(nahs[0].Network, net.JoinHostPort(nahs[0].Host, portStr), proxyURL, f)
if err != nil {
return nil, false, fmt.Errorf("first listen: %s", err)
return nil, false, errors.Wrap(err, "first listen")
}
defer func() {
if err != nil || retry {
@ -139,7 +140,7 @@ func listenAllRetry(nahs []networkAndHost, port int, proxyURL string, f firewall
if err != nil {
return ss,
missinggo.IsAddrInUse(err) && port == 0,
fmt.Errorf("subsequent listen: %s", err)
errors.Wrap(err, "subsequent listen")
}
ss = append(ss, s)
}