Only consider as slow consumers clients that did CONNECT

Under some scenarios a client may hit the slow consumer
write deadline during the connecting stage, meaning that
it is possible to consider unhealthy clients could not
finish the TLS handshake as slow consumers.

With this change, we only consider as slow consumers
clients that did connect to the cluster without issues.

Signed-off-by: Waldemar Quevedo <wally@synadia.com>
This commit is contained in:
Waldemar Quevedo
2018-12-18 21:51:38 -08:00
parent 0953016abe
commit 3cfc2fec29
2 changed files with 35 additions and 0 deletions

View File

@@ -856,6 +856,13 @@ func (c *client) flushOutbound() bool {
// here, and don't report a slow consumer error.
sce = false
}
} else if !c.flags.isSet(connectReceived) {
// Under some conditions, a client may hit a slow consumer write deadline
// before the authorization or TLS handshake timeout. If that is the case,
// then we handle as slow consumer though we do not increase the counter
// as can be misleading.
c.clearConnection(SlowConsumerWriteDeadline)
sce = false
}
if sce {
atomic.AddInt64(&srv.slowConsumers, 1)

View File

@@ -383,3 +383,31 @@ func TestTLSTimeoutNotReportSlowConsumer(t *testing.T) {
// ok
}
}
func TestNotReportSlowConsumerUnlessConnected(t *testing.T) {
oa, err := server.ProcessConfigFile("./configs/srv_a_tls.conf")
if err != nil {
t.Fatalf("Unable to load config file: %v", err)
}
// Override WriteDeadline to very small value so that handshake
// fails with a slow consumer error.
oa.WriteDeadline = 1 * time.Nanosecond
sa := RunServer(oa)
defer sa.Shutdown()
ch := make(chan string, 1)
cscl := &captureSlowConsumerLogger{ch: ch}
sa.SetLogger(cscl, false, false)
nc := createClientConn(t, oa.Host, oa.Port)
defer nc.Close()
// Make sure we don't get any Slow Consumer error.
select {
case e := <-ch:
t.Fatalf("Unexpected slow consumer error: %s", e)
case <-time.After(500 * time.Millisecond):
// ok
}
}