[lxc-devel] [lxd/master] client: Fix error handling in operations
stgraber on Github
lxc-bot at linuxcontainers.org
Tue Nov 6 22:55:13 UTC 2018
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 605 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20181106/cac2881d/attachment.bin>
-------------- next part --------------
From cd4b1ec3c6200b8ce9b941e997e276ca5680e2dc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 6 Nov 2018 17:52:48 -0500
Subject: [PATCH] client: Fix error handling in operations
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
If an error occured during setupListener, the boolean indicating that
setup was done wouldn't be set to true, causing a subsequent call to go
through and attempt initialization after the various channels had
already been closed.
Closes #5247
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
client/operations.go | 19 ++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)
diff --git a/client/operations.go b/client/operations.go
index f27df75b1a..63c6d227f9 100644
--- a/client/operations.go
+++ b/client/operations.go
@@ -83,11 +83,6 @@ func (op *operation) RemoveHandler(target *EventTarget) error {
// Refresh pulls the current version of the operation and updates the struct
func (op *operation) Refresh() error {
- // Don't bother with a manual update if we are listening for events
- if op.handlerReady {
- return nil
- }
-
// Get the current version of the operation
newOp, _, err := op.r.GetOperation(op.ID)
if err != nil {
@@ -136,6 +131,7 @@ func (op *operation) setupListener() error {
if op.handlerReady {
return nil
}
+ op.handlerReady = true
// Get a new listener
if op.listener == nil {
@@ -156,14 +152,14 @@ func (op *operation) setupListener() error {
op.handlerLock.Lock()
defer op.handlerLock.Unlock()
- // Get an operation struct out of this data
- newOp := op.extractOperation(data)
- if newOp == nil {
+ // Check if we're done already (because of another event)
+ if op.listener == nil {
return
}
- // Check if we're done already (because of another event)
- if op.listener == nil {
+ // Get an operation struct out of this data
+ newOp := op.extractOperation(data)
+ if newOp == nil {
return
}
@@ -232,8 +228,6 @@ func (op *operation) setupListener() error {
op.listener.Disconnect()
op.listener = nil
close(op.chActive)
-
- op.handlerReady = true
close(chReady)
if op.Err != "" {
@@ -244,7 +238,6 @@ func (op *operation) setupListener() error {
}
// Start processing background updates
- op.handlerReady = true
close(chReady)
return nil
More information about the lxc-devel
mailing list