Skip to content

Commit 3e703ae

Browse files
Add locking around the connection count to fix a data race. (#342)
Co-authored-by: andres-portainer <[email protected]>
1 parent 230f714 commit 3e703ae

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

share/tunnel/tunnel_in_proxy.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"io"
66
"net"
7+
"sync"
78

89
"github.com/jpillora/chisel/share/cio"
910
"github.com/jpillora/chisel/share/settings"
@@ -26,6 +27,7 @@ type Proxy struct {
2627
dialer net.Dialer
2728
tcp *net.TCPListener
2829
udp *udpListener
30+
mu sync.Mutex
2931
}
3032

3133
//NewProxy creates a Proxy
@@ -122,8 +124,12 @@ func (p *Proxy) runTCP(ctx context.Context) error {
122124

123125
func (p *Proxy) pipeRemote(ctx context.Context, src io.ReadWriteCloser) {
124126
defer src.Close()
127+
128+
p.mu.Lock()
125129
p.count++
126130
cid := p.count
131+
p.mu.Unlock()
132+
127133
l := p.Fork("conn#%d", cid)
128134
l.Debugf("Open")
129135
sshConn := p.sshTun.getSSH(ctx)

0 commit comments

Comments
 (0)