Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cancel all operations if c.V1Alpha2().Run fails. #8256

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions internal/app/machined/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/siderolabs/talos/internal/app/poweroff"
"github.com/siderolabs/talos/internal/app/trustd"
"github.com/siderolabs/talos/internal/app/wrapperd"
"github.com/siderolabs/talos/internal/pkg/ctxutil"
"github.com/siderolabs/talos/internal/pkg/mount"
"github.com/siderolabs/talos/pkg/httpdefaults"
"github.com/siderolabs/talos/pkg/machinery/api/common"
Expand Down Expand Up @@ -163,8 +164,6 @@ func runDebugServer(ctx context.Context) {

//nolint:gocyclo
func run() error {
errCh := make(chan error)

// Limit GOMAXPROCS.
startup.LimitMaxProcs(constants.MachinedMaxProcs)

Expand All @@ -179,8 +178,8 @@ func run() error {
return err
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx, cancel := context.WithCancelCause(context.Background())
defer cancel(nil)

drainer := runtime.NewDrainer()
defer func() {
Expand All @@ -195,7 +194,13 @@ func run() error {
go runDebugServer(ctx)

// Schedule service shutdown on any return.
defer system.Services(c.Runtime()).Shutdown(ctx)
s := system.Services(c.Runtime())
defer func() {
shutdownCtx, shutdownCtxCancel := context.WithTimeout(context.Background(), time.Minute)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required, because when we cancel the context, Shutdown(context) sequence below will never run properly.

defer shutdownCtxCancel()

s.Shutdown(shutdownCtx)
}()

// Start signal and ACPI listeners.
go func() {
Expand All @@ -211,7 +216,7 @@ func run() error {

log.Printf("controller runtime goroutine error: %s", ctrlErr)

errCh <- ctrlErr
cancel(ctrlErr)
}

log.Printf("controller runtime finished")
Expand Down Expand Up @@ -269,21 +274,23 @@ func run() error {
continue
}

errCh <- fmt.Errorf(
cancel(fmt.Errorf(
"fatal sequencer error in %q sequence: %v",
msg.GetSequence(),
msg.GetError().String(),
)
))
}
case *machine.RestartEvent:
errCh <- runtime.RebootError{Cmd: int(msg.Cmd)}
cancel(runtime.RebootError{Cmd: int(msg.Cmd)})
}
}
}
},
)

return <-errCh
<-ctx.Done()

return ctxutil.Cause(ctx)
DmitriyMV marked this conversation as resolved.
Show resolved Hide resolved
}

func main() {
Expand Down
3 changes: 2 additions & 1 deletion pkg/conditions/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package conditions

import (
"context"
"errors"
"strings"
"sync"

Expand Down Expand Up @@ -53,7 +54,7 @@ func (a *all) Wait(ctx context.Context) error {
// collapse errors if any of them is context canceled
if err != nil {
for _, e := range err.Errors {
if e == context.Canceled {
if errors.Is(e, context.Canceled) || errors.Is(e, context.DeadlineExceeded) {
return e
}
}
Expand Down