Skip to content

Commit

Permalink
check to return exit err if net/rpc call errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jrick committed Nov 8, 2024
1 parent 7a71769 commit 086829f
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions solverrpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ func startSolver() {
}()
}

func checkExit() error {
select {
case <-cmdDone:
return ErrSolverProcessExited
default:
return nil
}
}

// StartSolver starts the solver's background process. This can be used to
// detect errors starting the solver process before the first call to Roots.
func StartSolver() error {
Expand All @@ -95,8 +104,8 @@ func RootFactors(a []*big.Int, F *big.Int) ([]*big.Int, []int, error) {
return nil, nil, err
}

if _, ok := <-cmdDone; ok {
return nil, nil, ErrSolverProcessExited
if err := checkExit(); err != nil {
return nil, nil, err
}

var args struct {
Expand All @@ -111,6 +120,9 @@ func RootFactors(a []*big.Int, F *big.Int) ([]*big.Int, []int, error) {
}
err := client.Call("Solver.RootFactors", args, &result)
if err != nil {
if exitErr := checkExit(); exitErr != nil {
err = exitErr
}
return nil, nil, err
}
return result.Roots, result.Exponents, nil
Expand All @@ -128,8 +140,8 @@ func Roots(a []*big.Int, F *big.Int) ([]*big.Int, error) {
return nil, err
}

if _, ok := <-cmdDone; ok {
return nil, ErrSolverProcessExited
if err := checkExit(); err != nil {
return nil, err
}

var args struct {
Expand All @@ -144,6 +156,9 @@ func Roots(a []*big.Int, F *big.Int) ([]*big.Int, error) {
}
err := client.Call("Solver.Roots", args, &result)
if err != nil {
if exitErr := checkExit(); exitErr != nil {
err = exitErr
}
return nil, err
}
if result.RepeatedRoot != nil {
Expand Down

0 comments on commit 086829f

Please sign in to comment.