mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-10 23:11:01 +00:00
Merge pull request #1581 from jaffee/portmapper-npe
avoid nil pointer exception when failing to get listener
This commit is contained in:
commit
1af85a818b
1 changed files with 5 additions and 1 deletions
|
|
@ -30,6 +30,7 @@ import (
|
|||
"github.com/pilosa/pilosa/v2/testhook"
|
||||
"github.com/pilosa/pilosa/v2/topology"
|
||||
. "github.com/pilosa/pilosa/v2/vprint" // nolint:staticcheck
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// GlobalPortMap avoids many races and port conflicts when setting
|
||||
|
|
@ -53,7 +54,10 @@ func NewGlobalPortMapper(n int) (pm *GlobalPortMapper) {
|
|||
availPorts: make(map[int]net.Listener),
|
||||
}
|
||||
for i := 0; i < n; i++ {
|
||||
lsn, _ := net.Listen("tcp", ":0")
|
||||
lsn, err := net.Listen("tcp", ":0")
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "trying to listen on ephemeral port"))
|
||||
}
|
||||
r := lsn.Addr()
|
||||
port := r.(*net.TCPAddr).Port
|
||||
pm.availPorts[port] = lsn
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue