Skip to content

Commit abf50b7

Browse files
committed
chore: close listening socket when failing to accept connection
Signed-off-by: Alf-Rune Siqveland <alf.rune@northern.tech>
1 parent d6e7edb commit abf50b7

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

cmd/portforward_tcp.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ func (p *TCPPortForwarder) Run(
7171
for {
7272
conn, err := p.listen.Accept()
7373
if err != nil {
74+
close(acceptedConnections)
75+
fmt.Fprintf(os.Stderr,
76+
"error accepting new connection on socket %s: %s\n",
77+
p.listen.Addr(), err.Error(),
78+
)
79+
fmt.Fprintf(os.Stderr,
80+
"closing listening socket %s\n",
81+
p.listen.Addr(),
82+
)
7483
return
7584
}
7685
fmt.Printf(
@@ -85,7 +94,10 @@ func (p *TCPPortForwarder) Run(
8594
// handle new connections
8695
for {
8796
select {
88-
case conn := <-acceptedConnections:
97+
case conn, open := <-acceptedConnections:
98+
if !open {
99+
return
100+
}
89101
connectionUUID, _ := uuid.NewUUID()
90102
connectionID := connectionUUID.String()
91103
recvChan := make(chan *ws.ProtoMsg, portForwardTCPChannelSize)

0 commit comments

Comments
 (0)