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

fix: worker: listen for interrupt signals in GetStorageMinerAPI loop #11309

Merged
merged 3 commits into from
Nov 3, 2023
Merged
Changes from 2 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
23 changes: 18 additions & 5 deletions cmd/lotus-worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net"
"net/http"
"os"
"os/signal"
"path/filepath"
"reflect"
"strings"
Expand Down Expand Up @@ -348,6 +349,18 @@ var runCmd = &cli.Command{
// Connect to storage-miner
ctx := lcli.ReqContext(cctx)

// Create a new context with cancel function
ctx, cancel := context.WithCancel(ctx)
defer cancel()

// Listen for interrupt signals
go func() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
cancel()
}()

var nodeApi api.StorageMiner
var closer func()
for {
Expand All @@ -359,14 +372,14 @@ var runCmd = &cli.Command{
}
}
fmt.Printf("\r\x1b[0KConnecting to miner API... (%s)", err)
time.Sleep(time.Second)
continue
select {
case <-ctx.Done():
return xerrors.New("Interrupted by user")
case <-time.After(time.Second):
}
}

defer closer()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
Stebalien marked this conversation as resolved.
Show resolved Hide resolved

// Register all metric views
if err := view.Register(
metrics.DefaultViews...,
Expand Down