Skip to content

Commit 8c6ab53

Browse files
authored
Merge pull request #147 from arangodb-helper/starter-host-port-check-fix
Do not port check on any device when starter.host is given
2 parents d8e734d + 01385b5 commit 8c6ab53

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

service/bootstrap_master.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (s *Service) bootstrapMaster(ctx context.Context, runner Runner, config Con
4141
if err != nil {
4242
s.log.Fatalf("Cannot find HTTP server info: %#v", err)
4343
}
44-
if !WaitUntilPortAvailable(containerHTTPPort, time.Second*5) {
44+
if !WaitUntilPortAvailable(config.BindAddress, containerHTTPPort, time.Second*5) {
4545
s.log.Fatalf("Port %d is already in use", containerHTTPPort)
4646
}
4747

service/bootstrap_slave.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (s *Service) bootstrapSlave(peerAddress string, runner Runner, config Confi
113113
if err != nil {
114114
s.log.Fatalf("Cannot find HTTP server info: %#v", err)
115115
}
116-
if !WaitUntilPortAvailable(containerHTTPPort, time.Second*5) {
116+
if !WaitUntilPortAvailable(config.BindAddress, containerHTTPPort, time.Second*5) {
117117
s.log.Fatalf("Port %d is already in use", containerHTTPPort)
118118
}
119119

service/port_check.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
package service
2424

2525
import (
26-
"fmt"
2726
"net"
27+
"strconv"
2828
"time"
2929
)
3030

3131
// IsPortOpen checks if a TCP port is free to listen on.
32-
func IsPortOpen(port int) bool {
33-
l, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
32+
func IsPortOpen(host string, port int) bool {
33+
l, err := net.Listen("tcp", net.JoinHostPort(host, strconv.Itoa(port)))
3434
if err != nil {
3535
return false
3636
}
@@ -41,10 +41,10 @@ func IsPortOpen(port int) bool {
4141
// WaitUntilPortAvailable waits until a TCP port is free to listen on
4242
// or a timeout occurs.
4343
// Returns true when port is free to listen on.
44-
func WaitUntilPortAvailable(port int, timeout time.Duration) bool {
44+
func WaitUntilPortAvailable(host string, port int, timeout time.Duration) bool {
4545
start := time.Now()
4646
for {
47-
if IsPortOpen(port) {
47+
if IsPortOpen(host, port) {
4848
return true
4949
}
5050
if time.Since(start) >= timeout {

service/runtime_server_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func startServer(ctx context.Context, log *logging.Logger, runtimeContext runtim
131131
}
132132

133133
// Check availability of port
134-
if !WaitUntilPortAvailable(myPort, time.Second*3) {
134+
if !WaitUntilPortAvailable("", myPort, time.Second*3) {
135135
return nil, true, maskAny(fmt.Errorf("Cannot start %s, because port %d is already in use", serverType, myPort))
136136
}
137137

0 commit comments

Comments
 (0)