fix(proxy): count accepted tcp connections

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-04 12:07:32 +00:00
parent 78e740add7
commit fe2872149e
2 changed files with 30 additions and 2 deletions

View file

@ -52,7 +52,6 @@ func New(config *Config) (*Proxy, error) {
proxyInstance.miners[event.Miner.ID()] = event.Miner
proxyInstance.minerMu.Unlock()
}
statsValue.connections.Add(1)
current := proxyInstance.currentMiners.Add(1)
for {
maximum := statsValue.maxMiners.Load()
@ -321,6 +320,10 @@ func (p *Proxy) Upstreams() UpstreamStats {
}
func (p *Proxy) acceptConn(conn net.Conn, localPort uint16) {
if p != nil && p.stats != nil {
p.stats.connections.Add(1)
}
var tlsConfig *tls.Config
if _, ok := conn.(*tls.Conn); ok {
tlsConfig = &tls.Config{}

View file

@ -1,6 +1,9 @@
package proxy
import "testing"
import (
"net"
"testing"
)
func TestProxy_Reload_Good(t *testing.T) {
cfg := &Config{
@ -69,3 +72,25 @@ func TestProxy_CurrentMiners_Good(t *testing.T) {
t.Fatalf("expected first proxy miner count to return to 0, got %d", got)
}
}
func TestProxy_AcceptConn_Good(t *testing.T) {
cfg := &Config{
Mode: "nicehash",
Bind: []BindAddr{{Host: "127.0.0.1", Port: 3333}},
Pools: []PoolConfig{{URL: "pool-a:3333", Enabled: true}},
Workers: WorkersDisabled,
}
proxyValue, errorValue := New(cfg)
if errorValue != nil {
t.Fatal(errorValue)
}
serverConn, clientConn := net.Pipe()
proxyValue.acceptConn(serverConn, 3333)
if got := proxyValue.stats.connections.Load(); got != 1 {
t.Fatalf("expected connection counter to increment on accept, got %d", got)
}
_ = clientConn.Close()
_ = serverConn.Close()
}