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

Conversation

rjan90
Copy link
Contributor

@rjan90 rjan90 commented Oct 3, 2023

Proposed Changes

Listen for interrupt signals in GetStorageMinerAPI loop, allowing for graceful shutdown in case the worker is brought up before the lotus-miner process is running.

Additional Info

Before:

lotus-worker run
2023-10-03T04:19:52.209-0400    INFO    main    lotus-worker/main.go:296        Starting lotus worker
Connecting to miner API... (RPC client error: sendRequest failed: Post "http://10.2.2.22:2345/rpc/v0": context canceled)
Connecting to miner API... (RPC client error: sendRequest failed: Post "http://10.2.2.22:2345/rpc/v0": context canceled)
Connecting to miner API... (RPC client error: sendRequest failed: Post "http://10.2.2.22:2345/rpc/v0": context canceled)^C^C^C
Connecting to miner API... (RPC client error: sendRequest failed: Post "http://10.2.2.22:2345/rpc/v0": context canceled)^C

After:

lotus-worker run
2023-10-03T05:51:09.475-0400    INFO    main    lotus-worker/main.go:297        Starting lotus worker
Connecting to miner API... (RPC client error: sendRequest failed: Post "http://127.0.0.1:2345/rpc/v0": dial tcp 127.0.0.1:2345: connect: connection refused)^C2023-10-03T05:51:10.343-0400       WARN    main    lotus-worker/main.go:115 Interrupted by user:
    main.glob..func6
        /root/lotus/cmd/lotus-worker/main.go:352

Checklist

Before you mark the PR ready for review, please make sure that:

  • Commits have a clear commit message.
  • PR title is in the form of of <PR type>: <area>: <change being made>
    • example: fix: mempool: Introduce a cache for valid signatures
    • PR type: fix, feat, build, chore, ci, docs, perf, refactor, revert, style, test
    • area, e.g. api, chain, state, market, mempool, multisig, networking, paych, proving, sealing, wallet, deps
  • If the PR affects users (e.g., new feature, bug fix, system requirements change), update the CHANGELOG.md and add details to the UNRELEASED section.
  • New features have usage guidelines and / or documentation updates in
  • Tests exist for new functionality or change in behavior
  • CI is green

- Added a goroutine to listen for interrupt signals, which will cancel the current context when an interrupt signal is received. This allows for graceful shutdown of ongoing operations.
@rjan90 rjan90 changed the title fix: worker: listen for interrupt signals fix: worker: listen for interrupt signals in GetStorageMinerAPI loop Oct 3, 2023
@rjan90 rjan90 marked this pull request as ready for review October 3, 2023 09:59
@rjan90 rjan90 requested a review from a team as a code owner October 3, 2023 09:59
defer closer()
ctx, cancel := context.WithCancel(ctx)
ctx, cancel = context.WithCancel(ctx)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to drop this.

(also, this will re-assign cancel, leading to a data race with the goroutine above)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dropped this here: f759f4d

Remove redundant context cancellation in lotus worker
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit, otherwise LGTM. Sorry for the delay, I didn't notice your changes. Feel free to bug me on slack if I'm not responsive.

cmd/lotus-worker/main.go Outdated Show resolved Hide resolved
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, I just removed the offending line.

@Stebalien Stebalien enabled auto-merge (squash) November 3, 2023 13:28
@Stebalien Stebalien merged commit b1228b5 into master Nov 3, 2023
79 of 87 checks passed
@Stebalien Stebalien deleted the phi/fix-worker-graceful-disconnect branch November 3, 2023 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants