Skip to content

Commit 60cafbd

Browse files
committed
fix: support IPv6 in replica address discovery (#373)
Signed-off-by: Marvin Gaube <[email protected]>
1 parent f35ee57 commit 60cafbd

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

app/replica.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package app
2121

2222
import (
2323
"errors"
24+
"fmt"
2425
"net"
2526
"net/http"
2627
"os"
@@ -293,6 +294,7 @@ func startReplica(c *cli.Context) error {
293294
host, _ := os.Hostname()
294295
addrs, _ := net.LookupIP(host)
295296
for _, addr := range addrs {
297+
// first try: handle addr as v4 address
296298
if ipv4 := addr.To4(); ipv4 != nil {
297299
address = ipv4.String()
298300
if address == "127.0.0.1" {
@@ -301,7 +303,17 @@ func startReplica(c *cli.Context) error {
301303
}
302304
address = address + ":9502"
303305
break
306+
} else if ipv6 := addr.To16(); ipv6 != nil {
307+
// second try: handle addr as v6 address only if we know it is not v4
308+
address = ipv6.String()
309+
if address == "::1" {
310+
address = fmt.Sprintf("[%s]:9502", address)
311+
continue
312+
}
313+
address = fmt.Sprintf("[%s]:9502", address)
314+
break
304315
}
316+
305317
}
306318
}
307319
controlAddress, dataAddress, syncAddress, err := util.ParseAddresses(address)

0 commit comments

Comments
 (0)