Skip to content

Commit

Permalink
chore(nodebuilder): decrease lifecycle timeout for LN (#2290)
Browse files Browse the repository at this point in the history
LNs don't need that much time to run

Co-authored-by: rene <[email protected]>
  • Loading branch information
Wondertan and renaynay authored Jun 1, 2023
1 parent 1c1327b commit 218ab99
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
23 changes: 17 additions & 6 deletions nodebuilder/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import (
"github.com/celestiaorg/celestia-node/nodebuilder/state"
)

var Timeout = time.Minute * 2

var (
log = logging.Logger("node")
fxLog = logging.Logger("fx")
Expand Down Expand Up @@ -97,14 +95,15 @@ func NewWithConfig(tp node.Type, network p2p.Network, store Store, cfg *Config,

// Start launches the Node and all its components and services.
func (n *Node) Start(ctx context.Context) error {
ctx, cancel := context.WithTimeout(ctx, Timeout)
to := timeout(n.Type)
ctx, cancel := context.WithTimeout(ctx, to)
defer cancel()

err := n.start(ctx)
if err != nil {
log.Debugf("error starting %s Node: %s", n.Type, err)
if errors.Is(err, context.DeadlineExceeded) {
return fmt.Errorf("node: failed to start within timeout(%s): %w", Timeout, err)
return fmt.Errorf("node: failed to start within timeout(%s): %w", to, err)
}
return fmt.Errorf("node: failed to start: %w", err)
}
Expand Down Expand Up @@ -142,14 +141,15 @@ func (n *Node) Run(ctx context.Context) error {
// Canceling the given context earlier 'ctx' unblocks the Stop and aborts graceful shutdown forcing
// remaining Modules/Services to close immediately.
func (n *Node) Stop(ctx context.Context) error {
ctx, cancel := context.WithTimeout(ctx, Timeout)
to := timeout(n.Type)
ctx, cancel := context.WithTimeout(ctx, to)
defer cancel()

err := n.stop(ctx)
if err != nil {
log.Debugf("error stopping %s Node: %s", n.Type, err)
if errors.Is(err, context.DeadlineExceeded) {
return fmt.Errorf("node: failed to stop within timeout(%s): %w", Timeout, err)
return fmt.Errorf("node: failed to stop within timeout(%s): %w", to, err)
}
return fmt.Errorf("node: failed to stop: %w", err)
}
Expand Down Expand Up @@ -183,3 +183,14 @@ func newNode(opts ...fx.Option) (*Node, error) {

// lifecycleFunc defines a type for common lifecycle funcs.
type lifecycleFunc func(context.Context) error

var DefaultLifecycleTimeout = time.Minute * 2

func timeout(tp node.Type) time.Duration {
switch tp {
case node.Light:
return time.Second * 20
default:
return DefaultLifecycleTimeout
}
}
7 changes: 3 additions & 4 deletions nodebuilder/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ func StartMockOtelCollectorHTTPServer(t *testing.T) (string, func()) {
}

func TestEmptyBlockExists(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

var test = []struct {
tp node.Type
}{
Expand All @@ -149,10 +152,6 @@ func TestEmptyBlockExists(t *testing.T) {
for i, tt := range test {
t.Run(strconv.Itoa(i), func(t *testing.T) {
node := TestNode(t, tt.tp)

ctx, cancel := context.WithTimeout(context.Background(), Timeout)
defer cancel()

err := node.Start(ctx)
require.NoError(t, err)

Expand Down

0 comments on commit 218ab99

Please sign in to comment.