Merge pull request #3333 from nats-io/leaf_connect_disabled

Use specific boolean for a leaf test instead of using leafNodeEnabled
This commit is contained in:
Ivan Kozlovic
2022-08-04 14:33:31 -06:00
committed by GitHub
3 changed files with 14 additions and 7 deletions

View File

@@ -951,7 +951,7 @@ func (s *Server) closeAndDisableLeafnodes() {
leafs = append(leafs, ln)
}
// Disable leafnodes for now.
s.leafNodeEnabled = false
s.leafDisableConnect = true
s.mu.Unlock()
for _, ln := range leafs {

View File

@@ -495,12 +495,13 @@ func (s *Server) connectToRemoteLeafNode(remote *leafNodeCfg, firstConnect bool)
if url != rURL.Host {
ipStr = fmt.Sprintf(" (%s)", url)
}
if s.isLeafNodeEnabled() {
s.Debugf("Trying to connect as leafnode to remote server on %q%s", rURL.Host, ipStr)
conn, err = natsDialTimeout("tcp", url, dialTimeout)
} else {
// Some test may want to disable remotes from connecting
if s.isLeafConnectDisabled() {
s.Debugf("Will not attempt to connect to remote server on %q%s, leafnodes currently disabled", rURL.Host, ipStr)
err = ErrLeafNodeDisabled
} else {
s.Debugf("Trying to connect as leafnode to remote server on %q%s", rURL.Host, ipStr)
conn, err = natsDialTimeout("tcp", url, dialTimeout)
}
}
if err != nil {
@@ -569,10 +570,10 @@ func (s *Server) checkJetStreamMigrate(remote *leafNodeCfg) {
}
// Helper for checking.
func (s *Server) isLeafNodeEnabled() bool {
func (s *Server) isLeafConnectDisabled() bool {
s.mu.RLock()
defer s.mu.RUnlock()
return s.leafNodeEnabled
return s.leafDisableConnect
}
// Save off the tlsName for when we use TLS and mix hostnames and IPs. IPs usually

View File

@@ -164,6 +164,7 @@ type Server struct {
leafRemoteCfgs []*leafNodeCfg
leafRemoteAccounts sync.Map
leafNodeEnabled bool
leafDisableConnect bool // Used in test only
quitCh chan struct{}
startupComplete chan struct{}
@@ -1625,6 +1626,11 @@ func (s *Server) Start() {
// Avoid RACE between Start() and Shutdown()
s.mu.Lock()
s.running = true
// Update leafNodeEnabled in case options have changed post NewServer()
// and before Start() (we should not be able to allow that, but server has
// direct reference to user-provided options - at least before a Reload() is
// performed.
s.leafNodeEnabled = opts.LeafNode.Port != 0 || len(opts.LeafNode.Remotes) > 0
s.mu.Unlock()
s.grMu.Lock()