diff --git a/tcpproxy.go b/tcpproxy.go index 9bbc1a4..8a9bd4c 100644 --- a/tcpproxy.go +++ b/tcpproxy.go @@ -172,6 +172,8 @@ func (p *Proxy) AddRoute(ipPort string, dest Target) (routeID int) { // Both AddRoute and RemoveRoute is go-routine safe. func (p *Proxy) RemoveRoute(ipPort string, routeID int) { cfg := p.configFor(ipPort) + cfg.Lock() + defer cfg.Unlock() cfg.routes[routeID] = nil } @@ -255,6 +257,8 @@ func (p *Proxy) serveListener(ret chan<- error, ln net.Listener, cfg *config) { // It returns whether it matched purely for testing. func (p *Proxy) serveConn(c net.Conn, cfg *config) bool { br := bufio.NewReader(c) + cfg.Lock() + defer cfg.Unlock() for _, route := range cfg.routes { if route == nil { continue