[lxc-devel] [lxd/master] Fix Potential Event Race

jtopjian on Github lxc-bot at linuxcontainers.org
Tue Oct 9 01:58:10 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 475 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20181009/74174eec/attachment.bin>
-------------- next part --------------
From e3d0bc690f47f5971bbf99d784b75737eacc28ca Mon Sep 17 00:00:00 2001
From: Joe Topjian <joe at topjian.net>
Date: Tue, 9 Oct 2018 01:54:08 +0000
Subject: [PATCH] Fix Potential Event Race

This commit fixes a potential race condition when listening
for events and extracting operations by moving the lock
to before the operation struct is created.
---
 client/operations.go | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/client/operations.go b/client/operations.go
index fc015c220c..f27df75b1a 100644
--- a/client/operations.go
+++ b/client/operations.go
@@ -152,16 +152,16 @@ func (op *operation) setupListener() error {
 	_, err := op.listener.AddHandler([]string{"operation"}, func(data interface{}) {
 		<-chReady
 
+		// We don't want concurrency while processing events
+		op.handlerLock.Lock()
+		defer op.handlerLock.Unlock()
+
 		// Get an operation struct out of this data
 		newOp := op.extractOperation(data)
 		if newOp == nil {
 			return
 		}
 
-		// We don't want concurrency while processing events
-		op.handlerLock.Lock()
-		defer op.handlerLock.Unlock()
-
 		// Check if we're done already (because of another event)
 		if op.listener == nil {
 			return


More information about the lxc-devel mailing list