Skip to content

[tmpnet] Ensure all node runtime methods accept a context #3894

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

Merged
merged 2 commits into from
Apr 18, 2025

Conversation

maru-ava
Copy link
Contributor

@maru-ava maru-ava commented Apr 17, 2025

PR Chain: tmpnet+kube

This PR chain enables tmpnet to deploy temporary networks to Kubernetes. Early PRs refactor tmpnet to support the addition in #3615 of a new tmpnet node runtime for kube.

Why this should be merged

Previously, runtime methods didn't always require a context to interact with local processes. The kube runtime always involves network calls so a context is required.

How this was tested

C/I

Need to be documented in RELEASES.md?

N/A

TODO

@maru-ava maru-ava self-assigned this Apr 17, 2025
@maru-ava maru-ava added the tooling Build, test and development tooling label Apr 17, 2025
@github-project-automation github-project-automation bot moved this to Backlog 🗄️ in avalanchego Apr 17, 2025
@maru-ava maru-ava moved this from Backlog 🗄️ to In Review 👀 in avalanchego Apr 17, 2025
@maru-ava maru-ava force-pushed the tmpnet-ensure-logger branch from e05a502 to ed26001 Compare April 17, 2025 20:50
@maru-ava maru-ava force-pushed the tmpnet-ensure-context branch from 26072d7 to 5b2c08d Compare April 17, 2025 21:25
@maru-ava maru-ava removed the request for review from StephenButtolph April 17, 2025 21:25
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates node runtime methods to require a context parameter, ensuring that operations involving local processes can now be cancelled or time out appropriately.

  • Modified ProcessRuntime methods (readState, Start, InitiateStop) to accept a context.
  • Updated Node and Network configuration and runtime functions to propagate context parameters.
  • Adjusted test cases to use context when calling runtime functions.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/fixture/tmpnet/process_runtime.go Updated runtime methods to accept context parameters.
tests/fixture/tmpnet/node_config.go Modified Node.Read to propagate context to readState.
tests/fixture/tmpnet/node.go Updated NodeRuntime interface and methods to include context.
tests/fixture/tmpnet/network_test.go Adjusted tests to pass context to network read functions.
tests/fixture/tmpnet/network_config.go Propagated context through network readNodes and related calls.
tests/fixture/tmpnet/network.go Updated network functions to use context when calling methods.
tests/fixture/e2e/env.go Revised environment setup to pass context to network reads.

Comment on lines 231 to 237
func (p *ProcessRuntime) getProcess() (*os.Process, error) {
// Read the process context to ensure freshness. The node may have
// stopped or been restarted since last read.
if err := p.readState(); err != nil {
if err := p.readState(context.Background()); err != nil {
return nil, fmt.Errorf("failed to read process context: %w", err)
Copy link
Preview

Copilot AI Apr 18, 2025

Choose a reason for hiding this comment

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

Consider passing a meaningful context instead of context.Background() to ensure proper cancellation propagation.

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The context is necessary for the method, but it isn't used.

Copy link
Contributor

@joshua-kim joshua-kim Apr 18, 2025

Choose a reason for hiding this comment

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

context.Background() is generally reserved for the entry point into the program... so I feel like we should either not ignore this comment and expect getProcess to pass in a context, or just use context.TODO().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@michaelkaplan13 michaelkaplan13 left a comment

Choose a reason for hiding this comment

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

I agree with @joshua-kim on using context.TODO() in that one case (or passing a context to getProcess, but that doesn't seem necessary right now).

LGTM otherwise

@maru-ava maru-ava force-pushed the tmpnet-ensure-logger branch from ed26001 to aa5189d Compare April 18, 2025 20:12
@maru-ava maru-ava force-pushed the tmpnet-ensure-context branch from 5b2c08d to a61bdec Compare April 18, 2025 20:32
Base automatically changed from tmpnet-ensure-logger to master April 18, 2025 20:44
Previously, runtime methods didn't always require a context to
interact with local processes. The kube runtime almost always involves
network calls so a context is required.
@maru-ava maru-ava force-pushed the tmpnet-ensure-context branch from a61bdec to 8511fd9 Compare April 18, 2025 20:45
@maru-ava
Copy link
Contributor Author

Rebased

@maru-ava maru-ava enabled auto-merge April 18, 2025 20:45
@maru-ava maru-ava added this pull request to the merge queue Apr 18, 2025
Merged via the queue into master with commit dae0f00 Apr 18, 2025
24 checks passed
@maru-ava maru-ava deleted the tmpnet-ensure-context branch April 18, 2025 21:16
@github-project-automation github-project-automation bot moved this from In Review 👀 to Done ✅ in avalanchego Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tooling Build, test and development tooling
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants