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

refactor(engine): improve Engine.Start error handling #2322

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
25 changes: 16 additions & 9 deletions execution/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package engine

import (
"context"
"fmt"

ctypes "github.com/berachain/beacon-kit/consensus-types/types"
engineprimitives "github.com/berachain/beacon-kit/engine-primitives/engine-primitives"
Expand Down Expand Up @@ -58,17 +59,23 @@ func New(
}
}

// Start spawns any goroutines required by the service.
func (ee *Engine) Start(
ctx context.Context,
) error {
func (ee *Engine) Start(ctx context.Context) error {
errChan := make(chan error, 1)
go func() {
// TODO: handle better
if err := ee.ec.Start(ctx); err != nil {
panic(err)
}
if err := ee.ec.Start(ctx); err != nil {
ee.logger.Error("engine client failed to start", "error", err)
errChan <- err
return
}
close(errChan)
}()
return nil

select {
case err := <-errChan:
Copy link

Choose a reason for hiding this comment

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

This changes the behavior of Start. Previously, we'd exit as soon as goroutine was spawned. Now we're waiting for Start to finish (blocking select). What's the point of having a goroutine then?

return err
case <-ctx.Done():
return fmt.Errorf("engine client start cancelled: %w", ctx.Err())
}
}

// GetPayload returns the payload and blobs bundle for the given slot.
Expand Down