Merge pull request #301 from nspcc-dev/fix-sigsegv-on-failed-bind

connmgr: correctly pass binding error to the server
This commit is contained in:
Roman Khimov 2019-08-19 20:22:55 +03:00 committed by GitHub
commit bb2568cc53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 11 deletions

View file

@ -27,7 +27,13 @@ type Connmgr struct {
}
//New creates a new connection manager
func New(cfg Config) *Connmgr {
func New(cfg Config) (*Connmgr, error) {
listener, err := net.Listen("tcp", cfg.AddressPort)
if err != nil {
return nil, err
}
cnnmgr := &Connmgr{
cfg,
make(map[string]*Request),
@ -36,13 +42,6 @@ func New(cfg Config) *Connmgr {
}
go func() {
listener, err := net.Listen("tcp", cfg.AddressPort)
if err != nil {
fmt.Println("Error connecting to outbound ", err)
}
defer func() {
listener.Close()
}()
@ -59,7 +58,7 @@ func New(cfg Config) *Connmgr {
}()
return cnnmgr
return cnnmgr, nil
}
// NewRequest will make a new connection gets the address from address func in config

View file

@ -11,7 +11,7 @@ import (
iputils "github.com/CityOfZion/neo-go/pkg/wire/util/ip"
)
func setupConnManager(s *Server, port uint16) *connmgr.Connmgr {
func setupConnManager(s *Server, port uint16) (*connmgr.Connmgr, error) {
cfg := connmgr.Config{
GetAddress: s.getAddress,
OnAccept: s.onAccept,

View file

@ -63,7 +63,10 @@ func New(net protocol.Magic, port uint16) (*Server, error) {
s.smg = syncmgr
// Setup connection manager
connmgr := setupConnManager(s, port)
connmgr, err := setupConnManager(s, port)
if err != nil {
return nil, err
}
s.cmg = connmgr
// Setup peer config