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

[minor] Prefer signal.NotifyContext to signal.Notify in kanx #3180

Merged
merged 1 commit into from
Oct 10, 2024

Conversation

tdmanv
Copy link
Contributor

@tdmanv tdmanv commented Oct 10, 2024

Change Overview

signal.NotifyContext has been around since 1.16 and we should prefer it to signal.Notify.

https://pkg.go.dev/os/signal#NotifyContext

Pull request type

Please check the type of change your PR introduces:

  • 🚧 Work in Progress
  • 🌈 Refactoring (no functional changes, no api changes)
  • 🐹 Trivial/Minor
  • 🐛 Bugfix
  • 🌻 Feature
  • 🗺️ Documentation
  • 🤖 Test
  • 🏗️ Build

Issues

  • fixes #issue-number

Test Plan

Start Server

Server

./kando process server
{"File":"pkg/kando/process_server.go","Function":"github.com/kanisterio/kanister/pkg/kando.runProcessServer","Line":41,"address":{"Name":"/tmp/kanister.sock","Net":"unix"},"level":"info","msg":"Listening on socket","time":"2024-10-10T11:21:31.101779-07:00"}

Run Process

Client

./kando process client create -- tail -f /dev/null
Created process: pid:88226 state:PROCESS_STATE_RUNNING

Server

{"File":"pkg/kanx/kanx_grpc.pb.go","Function":"github.com/kanisterio/kanister/pkg/kanx._ProcessService_CreateProcesses_Handler","Line":190,"level":"info","msg":"pid:88226 state:PROCESS_STATE_RUNNING","stderr":"/var/folders/bf/c6ydxpp17p76y97j_yy_6n_m0000gp/T/kando.4170550590.stderr","stdout":"/var/folders/bf/c6ydxpp17p76y97j_yy_6n_m0000gp/T/kando.1518022560.stdout","time":"2024-10-10T11:23:11.573424-07:00"}

Send Interrupt ()

Server

^C{"File":"/opt/homebrew/Cellar/go/1.23.1/libexec/src/runtime/asm_arm64.s","Function":"runtime.goexit","Line":1223,"level":"info","msg":"Gracefully stopping. Parent context canceled","time":"2024-10-10T11:23:28.827767-07:00"}
{"File":"/opt/homebrew/Cellar/go/1.23.1/libexec/src/runtime/asm_arm64.s","Function":"runtime.goexit","Line":1223,"level":"info","msg":"pid:88226 state:PROCESS_STATE_FAILED exitCode:-1 exitErr:\"signal: interrupt\"","time":"2024-10-10T11:23:28.828545-07:00"}
  • 💪 Manual
  • ⚡ Unit test
  • 💚 E2E

@tdmanv tdmanv requested a review from aaron-kasten October 10, 2024 18:29
@tdmanv tdmanv added the kueue label Oct 10, 2024
Copy link
Contributor

@aaron-kasten aaron-kasten left a comment

Choose a reason for hiding this comment

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

Looks good!

@mergify mergify bot merged commit 691adf3 into master Oct 10, 2024
18 checks passed
@mergify mergify bot deleted the tom/kanx-notifycontext branch October 10, 2024 18:33
@@ -199,14 +199,14 @@ func NewServer() *Server {
}

func (s *Server) Serve(ctx context.Context, addr string) error {
stopChan := make(chan os.Signal, 1)
signal.Notify(stopChan, syscall.SIGTERM, syscall.SIGINT)
ctx, can := signal.NotifyContext(ctx, syscall.SIGTERM, syscall.SIGINT)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: make it explicit here can => cancel. It becomes easier to understand for the human reader.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on https://go.dev/wiki/CodeReviewComments#variable-names, maybe this should be c. The readable scope of the variable is 1 line, so i'd suggest a short variable name

Copy link
Contributor

@julio-lopez julio-lopez Oct 11, 2024

Choose a reason for hiding this comment

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

Tom, yes, in general variable names should be proportional to the context and so on.
In this case, cancel stop would be a better name for clarity, especially for the casual reviewer that looks at this code. It's about making it easy to understand the intent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants