diff --git a/server/const.go b/server/const.go index 48edbca2..65497d04 100644 --- a/server/const.go +++ b/server/const.go @@ -143,6 +143,9 @@ const ( // DEFAULT_LEAFNODE_INFO_WAIT Route dial timeout. DEFAULT_LEAFNODE_INFO_WAIT = 1 * time.Second + // DEFAULT_LEAFNODE_PORT is the default port for remote leafnode connections. + DEFAULT_LEAFNODE_PORT = 7422 + // DEFAULT_CONNECT_ERROR_REPORTS is the number of attempts at which a // repeated failed route, gateway or leaf node connection is reported. // This is used for initial connection, that is, when the server has diff --git a/server/opts.go b/server/opts.go index 4308b676..82bc76d0 100644 --- a/server/opts.go +++ b/server/opts.go @@ -2432,10 +2432,18 @@ func setBaselineOptions(opts *Options) { opts.LeafNode.AuthTimeout = float64(AUTH_TIMEOUT) / float64(time.Second) } } + // Set baseline connect port for remotes. + for _, r := range opts.LeafNode.Remotes { + if r != nil && r.URL.Port() == "" { + r.URL.Host = fmt.Sprintf("%s:%d", r.URL.Host, DEFAULT_LEAFNODE_PORT) + } + } + // Set this regardless of opts.LeafNode.Port if opts.LeafNode.ReconnectInterval == 0 { opts.LeafNode.ReconnectInterval = DEFAULT_LEAF_NODE_RECONNECT } + if opts.MaxControlLine == 0 { opts.MaxControlLine = MAX_CONTROL_LINE_SIZE } diff --git a/test/leafnode_test.go b/test/leafnode_test.go index 52ded516..3289c040 100644 --- a/test/leafnode_test.go +++ b/test/leafnode_test.go @@ -2330,3 +2330,27 @@ func TestLeafNodeDistributedQueueEvenly(t *testing.T) { } } } + +func TestLeafNodeDefaultPort(t *testing.T) { + o := testDefaultOptionsForLeafNodes() + o.LeafNode.Port = server.DEFAULT_LEAFNODE_PORT + s := RunServer(o) + defer s.Shutdown() + + conf := createConfFile(t, []byte(` + port: -1 + leaf { + remotes = [ + { + url: "leafnode://127.0.0.1" + } + ] + } + `)) + defer os.Remove(conf) + + sl, _ := RunServerWithConfig(conf) + defer sl.Shutdown() + + checkLeafNodeConnected(t, s) +}