Skip to content

Commit

Permalink
Fix CLI hanging with certain commands (#1730)
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink authored Sep 6, 2024
1 parent 67a5162 commit 5a1d3f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions cmd/flow/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package main

import (
"syscall"

"github.com/spf13/cobra"

"github.com/onflow/flow-cli/internal/accounts"
Expand Down Expand Up @@ -129,4 +131,10 @@ func main() {
if err := cmd.Execute(); err != nil {
util.Exit(1, err.Error())
}

// We are using a syscall because there is some dependency related to
// connecting to the network that is not being closed properly. This
// issue appeared with Go 1.23.1, but was not present in Go 1.22.
// It looks like this may be GRPC related from the stack trace.
syscall.Exit(command.StatusCode)
}
5 changes: 4 additions & 1 deletion internal/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ const (
logLevelNone = "none"
)

var StatusCode = 0

// AddToParent add new command to main parent cmd
// and initializes all necessary things as well as take care of errors and output
// here we can do all boilerplate code that is else copied in each command and make sure
Expand Down Expand Up @@ -171,7 +173,8 @@ func (c Command) AddToParent(parent *cobra.Command) {
if res, ok := result.(ResultWithExitCode); ok {
exitCode = res.ExitCode()
}
os.Exit(exitCode)

StatusCode = exitCode
}

bindFlags(c)
Expand Down

0 comments on commit 5a1d3f8

Please sign in to comment.