Skip to content

Commit

Permalink
DEBUG
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <[email protected]>
  • Loading branch information
stgraber committed Jan 18, 2024
1 parent cf47ad6 commit e237e8e
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 168 deletions.
14 changes: 14 additions & 0 deletions client/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/gorilla/websocket"

"github.com/lxc/incus/shared/api"
"github.com/lxc/incus/shared/logger"
)

// The Operation type represents an ongoing Incus operation (asynchronous processing).
Expand Down Expand Up @@ -120,28 +121,35 @@ func (op *operation) Wait() error {

// WaitContext lets you wait until the operation reaches a final state with context.Context.
func (op *operation) WaitContext(ctx context.Context) error {
logger.Errorf("stgraber: wait1")
if op.skipListener {
logger.Errorf("stgraber: wait2")
timeout := -1
deadline, ok := ctx.Deadline()
if ok {
timeout = int(time.Until(deadline).Seconds())
}
logger.Errorf("stgraber: wait3")

opAPI, _, err := op.r.GetOperationWait(op.ID, timeout)
if err != nil {
return err
}
logger.Errorf("stgraber: wait4")

op.Operation = *opAPI

if opAPI.Err != "" {
return errors.New(opAPI.Err)
}

logger.Errorf("stgraber: wait5")
return nil
}

logger.Errorf("stgraber: wait6")
op.handlerLock.Lock()
logger.Errorf("stgraber: wait7")
// Check if not done already
if op.StatusCode.IsFinal() {
if op.Err != "" {
Expand All @@ -150,28 +158,34 @@ func (op *operation) WaitContext(ctx context.Context) error {
}

op.handlerLock.Unlock()
logger.Errorf("stgraber: wait8")
return nil
}

logger.Errorf("stgraber: wait9")
op.handlerLock.Unlock()
logger.Errorf("stgraber: wait10")

// Make sure we have a listener setup
err := op.setupListener()
if err != nil {
return err
}
logger.Errorf("stgraber: wait11")

select {
case <-ctx.Done():
return ctx.Err()
case <-op.chActive:
}
logger.Errorf("stgraber: wait12")

// We're done, parse the result
if op.Err != "" {
return errors.New(op.Err)
}

logger.Errorf("stgraber: wait13")
return nil
}

Expand Down
1 change: 1 addition & 0 deletions cmd/incusd/api_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ func internalRefreshImage(d *Daemon, r *http.Request) response.Response {

err := autoUpdateImages(s.ShutdownCtx, s)
if err != nil {
logger.Errorf("refresh-image: %v", err)
return response.SmartError(err)
}

Expand Down
Loading

0 comments on commit e237e8e

Please sign in to comment.