Skip to content

Commit

Permalink
Added lock to strictly limit access to config.routes
Browse files Browse the repository at this point in the history
  • Loading branch information
yangchenyun committed May 23, 2018
1 parent 08e1ca7 commit a21b1c1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tcpproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a21b1c1

Please sign in to comment.