Rework startupComplete gate from PR #2360

The "InProcess" change make readyForConnections() possibly return
much faster than it used to, which could cause tests to fail.

Restore the original behavior, but in case of DontListen option
wait on the startupComplete gate.

Also fixed some missing checks for leafnode connections.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
This commit is contained in:
Ivan Kozlovic
2022-06-28 17:36:39 -06:00
parent dff1a33693
commit 5ed212ce04
2 changed files with 17 additions and 13 deletions

View File

@@ -6140,6 +6140,8 @@ func TestJetStreamClusterDomains(t *testing.T) {
strings.ReplaceAll(jsClusterTemplWithSingleLeafNode, "store_dir:", "extension_hint: will_extend, domain: CORE, store_dir:"))
defer ln.Shutdown()
checkLeafNodeConnectedCount(t, ln, 2)
// This shows we have extended this system.
c.waitOnPeerCount(4)
if ml := c.leader(); ml == ln {
@@ -6151,6 +6153,8 @@ func TestJetStreamClusterDomains(t *testing.T) {
spoke := c.createLeafNodeWithTemplate("LN-SPOKE", tmpl)
defer spoke.Shutdown()
checkLeafNodeConnectedCount(t, spoke, 2)
// Should be the same, should not extend the CORE domain.
c.waitOnPeerCount(4)
@@ -6643,6 +6647,8 @@ func TestJetStreamClusterLeafNodesWithoutJS(t *testing.T) {
ln := c.createLeafNodeWithTemplate("LN-SYS-S-NOJS", jsClusterTemplWithSingleLeafNodeNoJS)
defer ln.Shutdown()
checkLeafNodeConnectedCount(t, ln, 2)
// Check that we can access JS in the $G account on the cluster through the leafnode.
testJS(ln, "HUB", true)
ln.Shutdown()

View File

@@ -2949,19 +2949,6 @@ func (s *Server) ProfilerAddr() *net.TCPAddr {
}
func (s *Server) readyForConnections(d time.Duration) error {
end := time.Now().Add(d)
// Wait for startup. At this point AcceptLoop will only just be
// starting, so we'll still check for the presence of listeners
// after this.
select {
case <-s.startupComplete:
case <-time.After(d):
return fmt.Errorf(
"failed to be ready for connections after %s", d,
)
}
// Snapshot server options.
opts := s.getOpts()
@@ -2971,6 +2958,7 @@ func (s *Server) readyForConnections(d time.Duration) error {
}
chk := make(map[string]info)
end := time.Now().Add(d)
for time.Now().Before(end) {
s.mu.RLock()
chk["server"] = info{ok: s.listener != nil || opts.DontListen, err: s.listenerErr}
@@ -2988,6 +2976,16 @@ func (s *Server) readyForConnections(d time.Duration) error {
}
}
if numOK == len(chk) {
// In the case of DontListen option (no accept loop), we still want
// to make sure that Start() has done all the work, so we wait on
// that.
if opts.DontListen {
select {
case <-s.startupComplete:
case <-time.After(d):
return fmt.Errorf("failed to be ready for connections after %s: startup did not complete", d)
}
}
return nil
}
if d > 25*time.Millisecond {