From 3cfc2fec2980519ff2d4a6b12433db890ba49566 Mon Sep 17 00:00:00 2001 From: Waldemar Quevedo Date: Tue, 18 Dec 2018 21:51:38 -0800 Subject: [PATCH] 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 --- server/client.go | 7 +++++++ test/tls_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/server/client.go b/server/client.go index 76c61fa9..098c4bdc 100644 --- a/server/client.go +++ b/server/client.go @@ -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) diff --git a/test/tls_test.go b/test/tls_test.go index fbe16086..5a61d0fc 100644 --- a/test/tls_test.go +++ b/test/tls_test.go @@ -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 + } +}