[lxc-devel] [lxd/master] lxd/proxy: Fix goroutine leak
stgraber on Github
lxc-bot at linuxcontainers.org
Fri Apr 12 21:11:48 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190412/fc6d231e/attachment.bin>
-------------- next part --------------
From 252228d2007b7cb71effec420a588981abdd49d3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 12 Apr 2019 17:11:25 -0400
Subject: [PATCH] lxd/proxy: Fix goroutine leak
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Closes #5635
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/main_forkproxy.go | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/lxd/main_forkproxy.go b/lxd/main_forkproxy.go
index dd8a8cbaa4..328be0c53a 100644
--- a/lxd/main_forkproxy.go
+++ b/lxd/main_forkproxy.go
@@ -818,6 +818,7 @@ func proxyCopy(dst net.Conn, src net.Conn) error {
func genericRelay(dst net.Conn, src net.Conn, timeout bool) {
relayer := func(src net.Conn, dst net.Conn, ch chan error) {
ch <- proxyCopy(src, dst)
+ close(ch)
}
chSend := make(chan error)
@@ -825,8 +826,8 @@ func genericRelay(dst net.Conn, src net.Conn, timeout bool) {
go relayer(src, dst, chRecv)
- _, ok := dst.(*net.UDPConn)
- if !ok {
+ _, isUDP := dst.(*net.UDPConn)
+ if !isUDP {
go relayer(dst, src, chSend)
}
@@ -844,6 +845,12 @@ func genericRelay(dst net.Conn, src net.Conn, timeout bool) {
src.Close()
dst.Close()
+
+ // Empty the channels
+ if !isUDP {
+ <-chSend
+ }
+ <-chRecv
}
func unixRelayer(src *net.UnixConn, dst *net.UnixConn, ch chan bool) {
More information about the lxc-devel
mailing list