[lxc-devel] [lxd/master] Bugfixes

stgraber on Github lxc-bot at linuxcontainers.org
Wed Feb 15 05:04:11 UTC 2017


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/20170215/5bcad962/attachment.bin>
-------------- next part --------------
From d20bfb1fee560119779130a217f81cc356d9a1f2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 15 Feb 2017 00:03:30 -0500
Subject: [PATCH] Fix concurent read/write to s.conns in exec
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #2862

Signed-off-by: St├ęphane Graber <stgraber at ubuntu.com>
---
 lxd/container_exec.go | 36 +++++++++++++++++++++++++++++-------
 1 file changed, 29 insertions(+), 7 deletions(-)

diff --git a/lxd/container_exec.go b/lxd/container_exec.go
index 8cf048e..56da1ff 100644
--- a/lxd/container_exec.go
+++ b/lxd/container_exec.go
@@ -149,7 +149,11 @@ func (s *execWs) Do(op *operation) error {
 			}
 
 			for {
-				mt, r, err := s.conns[-1].NextReader()
+				s.connsLock.Lock()
+				conn := s.conns[-1]
+				s.connsLock.Unlock()
+
+				mt, r, err := conn.NextReader()
 				if mt == websocket.CloseMessage {
 					break
 				}
@@ -201,10 +205,16 @@ func (s *execWs) Do(op *operation) error {
 		}()
 
 		go func() {
-			readDone, writeDone := shared.WebsocketExecMirror(s.conns[0], ptys[0], ptys[0], attachedChildIsDead, int(ptys[0].Fd()))
+			s.connsLock.Lock()
+			conn := s.conns[0]
+			s.connsLock.Unlock()
+
+			readDone, writeDone := shared.WebsocketExecMirror(conn, ptys[0], ptys[0], attachedChildIsDead, int(ptys[0].Fd()))
+
 			<-readDone
 			<-writeDone
-			s.conns[0].Close()
+
+			conn.Close()
 			wgEOF.Done()
 		}()
 
@@ -213,10 +223,18 @@ func (s *execWs) Do(op *operation) error {
 		for i := 0; i < len(ttys); i++ {
 			go func(i int) {
 				if i == 0 {
-					<-shared.WebsocketRecvStream(ttys[i], s.conns[i])
+					s.connsLock.Lock()
+					conn := s.conns[i]
+					s.connsLock.Unlock()
+
+					<-shared.WebsocketRecvStream(ttys[i], conn)
 					ttys[i].Close()
 				} else {
-					<-shared.WebsocketSendStream(s.conns[i], ptys[i], -1)
+					s.connsLock.Lock()
+					conn := s.conns[i]
+					s.connsLock.Unlock()
+
+					<-shared.WebsocketSendStream(conn, ptys[i], -1)
 					ptys[i].Close()
 					wgEOF.Done()
 				}
@@ -229,12 +247,16 @@ func (s *execWs) Do(op *operation) error {
 			tty.Close()
 		}
 
-		if s.conns[-1] == nil {
+		s.connsLock.Lock()
+		conn := s.conns[-1]
+		s.connsLock.Unlock()
+
+		if conn == nil {
 			if s.interactive {
 				controlExit <- true
 			}
 		} else {
-			s.conns[-1].Close()
+			conn.Close()
 		}
 
 		attachedChildIsDead <- true


More information about the lxc-devel mailing list