From 49770a8f3a30516f816825a2e8b07d5a6afc18d7 Mon Sep 17 00:00:00 2001 From: Yuxuan 'fishy' Wang Date: Tue, 1 Feb 2022 13:55:34 -0800 Subject: [PATCH] Fix thriftbp.CountedTServerTransport Call Add(1) in Accept as for server TTransport its Open was never explicitly called. --- thriftbp/server_transport.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/thriftbp/server_transport.go b/thriftbp/server_transport.go index 3ca43a8d9..19bb24bda 100644 --- a/thriftbp/server_transport.go +++ b/thriftbp/server_transport.go @@ -11,17 +11,23 @@ import ( const meterNameTransportConnCounter = "thrift.connections" +// CountedTServerTransport is a wrapper around thrift.TServerTransport that +// emits a gauge of the number of client connections. type CountedTServerTransport struct { thrift.TServerTransport } +// Accept implements thrift.TServerTransport by retruning a thrift.TTransport +// that counts the number of client connections. func (m *CountedTServerTransport) Accept() (thrift.TTransport, error) { transport, err := m.TServerTransport.Accept() if err != nil { return nil, err } - return newCountedTTransport(transport), nil + wrappedTransport := newCountedTTransport(transport) + wrappedTransport.gauge.Add(1) + return wrappedTransport, nil } type countedTTransport struct { @@ -31,7 +37,7 @@ type countedTTransport struct { closeOnce sync.Once } -func newCountedTTransport(transport thrift.TTransport) thrift.TTransport { +func newCountedTTransport(transport thrift.TTransport) *countedTTransport { return &countedTTransport{ TTransport: transport, gauge: metricsbp.M.RuntimeGauge(meterNameTransportConnCounter),