Skip to content

Commit

Permalink
Improve goal node start error reporting in case of algod errored (alg…
Browse files Browse the repository at this point in the history
…orand#1513)

Improve node error reporting in case of algod errors
  • Loading branch information
tsachiherman authored Sep 23, 2020
1 parent 648552a commit a4528a3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
11 changes: 5 additions & 6 deletions nodecontrol/algodControl.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,8 @@ func (nc *NodeController) StartAlgod(args AlgodStartArgs) (alreadyRunning bool,
errLogger.SetLinePrefix(linePrefix)
outLogger.SetLinePrefix(linePrefix)
}

// Wait on the algod process and check if exits
algodExitChan := make(chan struct{})
algodExitChan := make(chan error, 1)
startAlgodCompletedChan := make(chan struct{})
defer close(startAlgodCompletedChan)
go func() {
Expand All @@ -202,14 +201,14 @@ func (nc *NodeController) StartAlgod(args AlgodStartArgs) (alreadyRunning bool,
}
default:
}
algodExitChan <- struct{}{}
algodExitChan <- err
}()

success := false
for !success {
select {
case <-algodExitChan:
return false, errAlgodExitedEarly
case err := <-algodExitChan:
err = &errAlgodExitedEarly{err}
return false, err
case <-time.After(time.Millisecond * 100):
// If we can't talk to the API yet, spin
algodClient, err := nc.AlgodClient()
Expand Down
16 changes: 15 additions & 1 deletion nodecontrol/nodeControlErrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ import (
"fmt"
)

var errAlgodExitedEarly = fmt.Errorf("node exited before we could contact it")
var errKMDDataDirNotAbs = fmt.Errorf("kmd data dir must be absolute path")
var errKMDExitedEarly = fmt.Errorf("kmd exited before we could contact it")

type errAlgodExitedEarly struct {
innerError error
}

func (e *errAlgodExitedEarly) Error() string {
if e.innerError == nil {
return "node exited before we could contact it"
}
return fmt.Sprintf("node exited with an error code, check node.log for more details : %v", e.innerError)
}

func (e *errAlgodExitedEarly) Unwrap(err error) error {
return e.innerError
}
19 changes: 19 additions & 0 deletions test/e2e-go/cli/goal/expect/goalNodeTest.exp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ if { [catch {
# Stop node
::AlgorandGoal::StopNode $TEST_PRIMARY_NODE_DIR

# "break" the node by replacing it's ledger data files with "broken" ones.
lassign [exec find $TEST_PRIMARY_NODE_DIR -name "ledger.tracker.sqlite"] PRIMARY_TRACKER_DATABASE_FILE
exec find $TEST_PRIMARY_NODE_DIR -name "ledger.tracker.sqlite*" -delete
exec -- echo "1234" > $PRIMARY_TRACKER_DATABASE_FILE

# try to start the primary node, and observe the expected failuire
set timeout 15
spawn goal node start -d $TEST_PRIMARY_NODE_DIR
expect {
timeout { close; ::AlgorandGoal::Abort "starting node exceeded timeout" }
-re {^Algorand node failed to start: node exited with an error code, check node\.log for more details : exit status 1} {puts "Expected failuire : node failed to start"; close}
eof { ::AlgorandGoal::Abort "eof received before the expected output " }
}
lassign [::AlgorandGoal::CheckProcessReturnedCode 0] ERROR_CODE
if {$ERROR_CODE != 1} {
puts "Node was expected to fail with 1 due to invalid ledger file, but returned error code $ERROR_CODE instead"
exit 1
}

# Shutdown the network
::AlgorandGoal::StopNetwork $NETWORK_NAME $TEST_ALGO_DIR $TEST_ROOT_DIR

Expand Down

0 comments on commit a4528a3

Please sign in to comment.