revert bind port to 0

This commit is contained in:
Kuba Podgórski 2021-01-14 18:33:22 +01:00
parent 36f17eee1d
commit 33c4c77495
2 changed files with 22 additions and 19 deletions

View file

@ -30,7 +30,6 @@ import (
"github.com/pilosa/pilosa/v2/encoding/proto"
"github.com/pilosa/pilosa/v2/http"
"github.com/pilosa/pilosa/v2/server"
"github.com/pilosa/pilosa/v2/test/port"
"github.com/pilosa/pilosa/v2/testhook"
)
@ -72,19 +71,29 @@ func newCommand(tb testing.TB, opts ...server.CommandOption) *Command {
m.Config.DataDir = path
defaultConf := server.NewConfig()
if err := port.GetPorts(func(ports []int) error {
if m.Config.Bind == defaultConf.Bind {
m.Config.Bind = fmt.Sprintf("http://localhost:%d", ports[0])
}
if m.Config.BindGRPC == defaultConf.BindGRPC {
m.Config.BindGRPC = fmt.Sprintf("http://localhost:%d", ports[1])
}
return nil
}, 2, 10); err != nil {
panic(err)
if m.Config.Bind == defaultConf.Bind {
m.Config.Bind = "http://localhost:0"
}
if m.Config.BindGRPC == defaultConf.BindGRPC {
m.Config.BindGRPC = "http://localhost:0"
}
/*
if err := port.GetPorts(func(ports []int) error {
if m.Config.Bind == defaultConf.Bind {
m.Config.Bind = fmt.Sprintf("http://localhost:%d", ports[0])
}
if m.Config.BindGRPC == defaultConf.BindGRPC {
m.Config.BindGRPC = fmt.Sprintf("http://localhost:%d", ports[1])
}
return nil
}, 2, 10); err != nil {
panic(err)
}
*/
m.Config.Translation.MapSize = 140000
m.Config.WorkerPoolSize = 2

View file

@ -19,7 +19,6 @@ import (
"log"
"net"
"strings"
"sync"
"syscall"
)
@ -32,12 +31,7 @@ func GetPort(wrapper func(int) error, retries int) error {
return GetPorts(f, 1, retries)
}
var mu = &sync.Mutex{}
func GetPorts(wrapper func([]int) error, requestedPorts, retries int) error {
mu.Lock()
defer mu.Unlock()
for i := 0; i < retries; i++ {
// get all requested ports
listeners := make([]net.Listener, requestedPorts)
@ -60,7 +54,7 @@ func GetPorts(wrapper func([]int) error, requestedPorts, retries int) error {
// send to wrapper and check output error
err := wrapper(ports)
if (err != nil) && (err == syscall.EADDRINUSE || strings.Contains(err.Error(), "address already in use")) {
log.Println("[port_mapper] address already in use error calling the wrapper", err)
log.Printf("[port_mapper: %+v] address already in use error calling the wrapper: %v\n", ports, err)
// only retry on address already in use error
continue
}