mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-08 20:07:51 +00:00
avoid nil pointer exception when failing to get listener
instead of an opaque NPE on the next line, panic with explicit error telling you what went wrong (in my case it was too many open files)
This commit is contained in:
parent
7d1f9e33b8
commit
8274a8cfee
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