[lxc-devel] [lxd/master] proxy: Add locking around UDP timer

stgraber on Github lxc-bot at linuxcontainers.org
Mon Feb 25 08:44:35 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/20190225/c7694e78/attachment.bin>
-------------- next part --------------
From 68eea39e9c8847c5ce87144f63ec19c93c666a75 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 25 Feb 2019 09:42:49 +0100
Subject: [PATCH] proxy: Add locking around UDP timer
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #5487

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/main_forkproxy.go | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lxd/main_forkproxy.go b/lxd/main_forkproxy.go
index 914c44bad2..0a8d7fd242 100644
--- a/lxd/main_forkproxy.go
+++ b/lxd/main_forkproxy.go
@@ -302,9 +302,10 @@ var udpSessions = map[string]*udpSession{}
 var udpSessionsLock sync.Mutex
 
 type udpSession struct {
-	client net.Addr
-	target net.Conn
-	timer  *time.Timer
+	client    net.Addr
+	target    net.Conn
+	timer     *time.Timer
+	timerLock sync.Mutex
 }
 
 func (c *cmdForkproxy) Command() *cobra.Command {
@@ -740,7 +741,10 @@ func proxyCopy(dst net.Conn, src net.Conn) error {
 					})
 				}
 
+				us.timerLock.Lock()
 				us.timer.Reset(30 * time.Minute)
+				us.timerLock.Unlock()
+
 				dst = us.target
 				dstUdp, dstIsUdp = dst.(*net.UDPConn)
 			}
@@ -775,7 +779,9 @@ func proxyCopy(dst net.Conn, src net.Conn) error {
 					return fmt.Errorf("Connection expired")
 				}
 
+				us.timerLock.Lock()
 				us.timer.Reset(30 * time.Minute)
+				us.timerLock.Unlock()
 
 				nw, ew = dstUdp.WriteTo(buf[0:nr], us.client)
 			} else {


More information about the lxc-devel mailing list