Skip to content

Commit

Permalink
Fix thriftbp.CountedTServerTransport
Browse files Browse the repository at this point in the history
Call Add(1) in Accept as for server TTransport its Open was never
explicitly called.
  • Loading branch information
fishy committed Feb 2, 2022
1 parent 8696800 commit 49770a8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions thriftbp/server_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
Expand Down

0 comments on commit 49770a8

Please sign in to comment.