Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8df1cb3

Browse files
committedMay 10, 2019
[CHANGED] DefaultURL changed to "nats://127.0.0.1:4222"
Replaced to loopback ipv4 instead of localhost. In some cases, when running the server with 127.0.0.1, if the application uses the previous default URL (localhost), the library would resolve this and possibly get 2 IPs (common to get 127.0.0.1 and ::1), and it would then pick randomly one of those 2. If getting ::1, and the server is listening on 127.0.0.1, the connection would fail before it tries with the ipv4 address. Also replaced reference of gnatsd with nats-server. Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
1 parent 36d30b0 commit 8df1cb3

9 files changed

+34
-34
lines changed
 

‎.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ go:
66
go_import_path: github.com/nats-io/go-nats
77
install:
88
- go get -t ./...
9-
- go get github.com/nats-io/gnatsd
9+
- go get github.com/nats-io/nats-server
1010
- go get github.com/mattn/goveralls
1111
- go get github.com/wadey/gocovmerge
1212
- go get -u honnef.co/go/tools/cmd/staticcheck

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ A [Go](http://golang.org) client for the [NATS messaging system](https://nats.io
1212
go get github.com/nats-io/go-nats
1313

1414
# Server
15-
go get github.com/nats-io/gnatsd
15+
go get github.com/nats-io/nats-server
1616
```
1717

1818
## Basic Usage

‎nats.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import (
4444
// Default Constants
4545
const (
4646
Version = "1.7.2"
47-
DefaultURL = "nats://localhost:4222"
47+
DefaultURL = "nats://127.0.0.1:4222"
4848
DefaultPort = 4222
4949
DefaultMaxReconnect = 60
5050
DefaultReconnectWait = 2 * time.Second

‎nats_test.go

+17-17
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ import (
3636
"testing"
3737
"time"
3838

39-
"github.com/nats-io/gnatsd/server"
40-
gnatsd "github.com/nats-io/gnatsd/test"
39+
"github.com/nats-io/nats-server/server"
40+
natsserver "github.com/nats-io/nats-server/test"
4141
"github.com/nats-io/nkeys"
4242
)
4343

@@ -112,13 +112,13 @@ var reconnectOpts = Options{
112112
}
113113

114114
func RunServerOnPort(port int) *server.Server {
115-
opts := gnatsd.DefaultTestOptions
115+
opts := natsserver.DefaultTestOptions
116116
opts.Port = port
117117
return RunServerWithOptions(&opts)
118118
}
119119

120120
func RunServerWithOptions(opts *server.Options) *server.Server {
121-
return gnatsd.RunServer(opts)
121+
return natsserver.RunServer(opts)
122122
}
123123

124124
func TestReconnectServerStats(t *testing.T) {
@@ -1045,25 +1045,25 @@ func TestAsyncINFO(t *testing.T) {
10451045
if err != nil || c.ps.state != OP_START {
10461046
t.Fatalf("Unexpected: %d : %v\n", c.ps.state, err)
10471047
}
1048-
// Pool now should contain localhost:4222 (the default URL) and localhost:5222
1049-
checkPool("localhost:4222", "localhost:5222")
1048+
// Pool now should contain 127.0.0.1:4222 (the default URL), localhost:4222 and localhost:5222
1049+
checkPool("127.0.0.1:4222", "localhost:4222", "localhost:5222")
10501050

10511051
// Make sure that if client receives the same, it is not added again.
10521052
err = c.parse(info)
10531053
if err != nil || c.ps.state != OP_START {
10541054
t.Fatalf("Unexpected: %d : %v\n", c.ps.state, err)
10551055
}
1056-
// Pool should still contain localhost:4222 (the default URL) and localhost:5222
1057-
checkPool("localhost:4222", "localhost:5222")
1056+
// Pool should still contain 127.0.0.1:4222 (the default URL), localhost:4222 and localhost:5222
1057+
checkPool("127.0.0.1:4222", "localhost:4222", "localhost:5222")
10581058

10591059
// Receive a new URL
10601060
info = []byte("INFO {\"connect_urls\":[\"localhost:4222\", \"localhost:5222\", \"localhost:6222\"]}\r\n")
10611061
err = c.parse(info)
10621062
if err != nil || c.ps.state != OP_START {
10631063
t.Fatalf("Unexpected: %d : %v\n", c.ps.state, err)
10641064
}
1065-
// Pool now should contain localhost:4222 (the default URL) localhost:5222 and localhost:6222
1066-
checkPool("localhost:4222", "localhost:5222", "localhost:6222")
1065+
// Pool now should contain 127.0.0.1:4222 (the default URL), localhost:4222, localhost:5222 and localhost:6222
1066+
checkPool("127.0.0.1:4222", "localhost:4222", "localhost:5222", "localhost:6222")
10671067

10681068
// Check that pool may be randomized on setup, but new URLs are always
10691069
// added at end of pool.
@@ -1130,7 +1130,7 @@ func TestConnServers(t *testing.T) {
11301130
}
11311131

11321132
// check the default url
1133-
validateURLs(c.Servers(), "nats://localhost:4222")
1133+
validateURLs(c.Servers(), "nats://127.0.0.1:4222")
11341134
if len(c.DiscoveredServers()) != 0 {
11351135
t.Fatalf("Expected no discovered servers")
11361136
}
@@ -1141,7 +1141,7 @@ func TestConnServers(t *testing.T) {
11411141
t.Fatalf("Unexpected: %d : %v\n", c.ps.state, err)
11421142
}
11431143
// Server list should now contain both the default and the new url.
1144-
validateURLs(c.Servers(), "nats://localhost:4222", "nats://localhost:5222")
1144+
validateURLs(c.Servers(), "nats://127.0.0.1:4222", "nats://localhost:5222")
11451145
// Discovered servers should only contain the new url.
11461146
validateURLs(c.DiscoveredServers(), "nats://localhost:5222")
11471147

@@ -1302,7 +1302,7 @@ SUAMK2FG4MI6UE3ACF3FK3OIQBCEIEZV7NSWFFEW63UXMRLFM2XLAXK4GY
13021302
func runTrustServer() *server.Server {
13031303
kp, _ := nkeys.FromSeed(oSeed)
13041304
pub, _ := kp.PublicKey()
1305-
opts := gnatsd.DefaultTestOptions
1305+
opts := natsserver.DefaultTestOptions
13061306
opts.Port = TEST_PORT
13071307
opts.TrustedKeys = []string{string(pub)}
13081308
s := RunServerWithOptions(&opts)
@@ -1407,7 +1407,7 @@ func TestUserCredentialsChainedFileNotFoundError(t *testing.T) {
14071407
// Setup opts for both servers.
14081408
kp, _ := nkeys.FromSeed(oSeed)
14091409
pub, _ := kp.PublicKey()
1410-
opts := gnatsd.DefaultTestOptions
1410+
opts := natsserver.DefaultTestOptions
14111411
opts.Port = -1
14121412
opts.Cluster.Port = -1
14131413
opts.TrustedKeys = []string{string(pub)}
@@ -1466,7 +1466,7 @@ func TestNkeyAuth(t *testing.T) {
14661466
kp, _ := nkeys.FromSeed(seed)
14671467
pub, _ := kp.PublicKey()
14681468

1469-
sopts := gnatsd.DefaultTestOptions
1469+
sopts := natsserver.DefaultTestOptions
14701470
sopts.Port = TEST_PORT
14711471
sopts.Nkeys = []*server.NkeyUser{&server.NkeyUser{Nkey: string(pub)}}
14721472
ts := RunServerWithOptions(&sopts)
@@ -1633,7 +1633,7 @@ func TestLookupHostResultIsRandomized(t *testing.T) {
16331633
t.Skip("Was looking for IPv4 and IPv6 addresses for localhost to perform test")
16341634
}
16351635

1636-
opts := gnatsd.DefaultTestOptions
1636+
opts := natsserver.DefaultTestOptions
16371637
opts.Host = "127.0.0.1"
16381638
opts.Port = TEST_PORT
16391639
s1 := RunServerWithOptions(&opts)
@@ -1667,7 +1667,7 @@ func TestLookupHostResultIsNotRandomizedWithNoRandom(t *testing.T) {
16671667
t.Skip("Was looking for IPv4 and IPv6 addresses for localhost to perform test")
16681668
}
16691669

1670-
opts := gnatsd.DefaultTestOptions
1670+
opts := natsserver.DefaultTestOptions
16711671
opts.Host = orgAddrs[0]
16721672
opts.Port = TEST_PORT
16731673
s1 := RunServerWithOptions(&opts)

‎test/auth_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import (
2020
"testing"
2121
"time"
2222

23-
"github.com/nats-io/gnatsd/server"
24-
"github.com/nats-io/gnatsd/test"
2523
"github.com/nats-io/go-nats"
24+
"github.com/nats-io/nats-server/server"
25+
"github.com/nats-io/nats-server/test"
2626
)
2727

2828
func TestAuth(t *testing.T) {

‎test/cluster_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import (
2323
"testing"
2424
"time"
2525

26-
"github.com/nats-io/gnatsd/server"
27-
"github.com/nats-io/gnatsd/test"
2826
"github.com/nats-io/go-nats"
27+
"github.com/nats-io/nats-server/server"
28+
"github.com/nats-io/nats-server/test"
2929
)
3030

3131
var testServers = []string{

‎test/conn_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ import (
2929
"testing"
3030
"time"
3131

32-
"github.com/nats-io/gnatsd/server"
33-
"github.com/nats-io/gnatsd/test"
3432
"github.com/nats-io/go-nats"
33+
"github.com/nats-io/nats-server/server"
34+
"github.com/nats-io/nats-server/test"
3535
)
3636

3737
func TestDefaultConnection(t *testing.T) {

‎test/helper_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import (
2020
"strings"
2121
"time"
2222

23-
"github.com/nats-io/gnatsd/server"
2423
"github.com/nats-io/go-nats"
24+
"github.com/nats-io/nats-server/server"
2525

26-
gnatsd "github.com/nats-io/gnatsd/test"
26+
natsserver "github.com/nats-io/nats-server/test"
2727
)
2828

2929
// So that we can pass tests and benchmarks...
@@ -78,7 +78,7 @@ func NewDefaultConnection(t tLogger) *nats.Conn {
7878

7979
// NewConnection forms connection on a given port.
8080
func NewConnection(t tLogger, port int) *nats.Conn {
81-
url := fmt.Sprintf("nats://localhost:%d", port)
81+
url := fmt.Sprintf("nats://127.0.0.1:%d", port)
8282
nc, err := nats.Connect(url)
8383
if err != nil {
8484
t.Fatalf("Failed to create default connection: %v\n", err)
@@ -97,7 +97,7 @@ func NewEConn(t tLogger) *nats.EncodedConn {
9797
}
9898

9999
////////////////////////////////////////////////////////////////////////////////
100-
// Running gnatsd server in separate Go routines
100+
// Running nats server in separate Go routines
101101
////////////////////////////////////////////////////////////////////////////////
102102

103103
// RunDefaultServer will run a server on the default port.
@@ -107,17 +107,17 @@ func RunDefaultServer() *server.Server {
107107

108108
// RunServerOnPort will run a server on the given port.
109109
func RunServerOnPort(port int) *server.Server {
110-
opts := gnatsd.DefaultTestOptions
110+
opts := natsserver.DefaultTestOptions
111111
opts.Port = port
112112
return RunServerWithOptions(opts)
113113
}
114114

115115
// RunServerWithOptions will run a server with the given options.
116116
func RunServerWithOptions(opts server.Options) *server.Server {
117-
return gnatsd.RunServer(&opts)
117+
return natsserver.RunServer(&opts)
118118
}
119119

120120
// RunServerWithConfig will run a server with the given configuration file.
121121
func RunServerWithConfig(configFile string) (*server.Server, *server.Options) {
122-
return gnatsd.RunServerWithConfig(configFile)
122+
return natsserver.RunServerWithConfig(configFile)
123123
}

‎test/reconnect_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222
"testing"
2323
"time"
2424

25-
"github.com/nats-io/gnatsd/server"
2625
"github.com/nats-io/go-nats"
26+
"github.com/nats-io/nats-server/server"
2727
)
2828

2929
func startReconnectServer(t *testing.T) *server.Server {

0 commit comments

Comments
 (0)
Failed to load comments.