Skip to content

Conversation

pablochacin
Copy link
Contributor

@pablochacin pablochacin commented Apr 24, 2025

What?

Handle signals in the parent process when calling a subprocess.

Why?

Prevent the parent from ending prematurely before the subprocess ends.

Also fixes #4735. By separating the Start of the process from waiting for the child to end, we can handle separately errors like binary not found (and report them) from the non-zero return codes from the child.

Checklist

  • I have performed a self-review of my code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests for my changes.
  • I have run linter and tests locally (make check) and all pass.

Checklist: Documentation (only for k6 maintainers and if relevant)

Please do not merge this PR until the following items are filled out.

  • I have added the correct milestone and labels to the PR.
  • I have updated the release notes: link
  • I have updated or added an issue to the k6-documentation: grafana/k6-docs#NUMBER if applicable
  • I have updated or added an issue to the TypeScript definitions: grafana/k6-DefinitelyTyped#NUMBER if applicable

Related PR(s)/Issue(s)

Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
@pablochacin pablochacin marked this pull request as ready for review April 24, 2025 17:29
@pablochacin pablochacin requested a review from a team as a code owner April 24, 2025 17:29
@pablochacin pablochacin marked this pull request as draft April 24, 2025 17:32
@pablochacin pablochacin marked this pull request as ready for review April 24, 2025 17:33
Copy link
Contributor

@oleiade oleiade left a comment

Choose a reason for hiding this comment

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

TL;DR: Confirming it works as expected, even on Windows. I feel comfortable merging as-is in the spirit of getting v1 in time.

Can confirm this works as expected, even on Windows. I think we could test it more thoroughly, especially on Windows, and I agree with the TODO comment that we should probably have a timeout forcing the process group to exit in case it takes too long or never does (considering OOMs and 100% CPU tests are still a thing, it might be a potential issue with signals never arriving).

I'll open an issue to track those topics, and make sure it's on the map for the next release.

Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

Comment on lines 167 to 169
case <-sigC:
// TODO: maybe we should set a timeout while waiting for the subprocess
gs.Logger.Debug("Signal received. Waiting for subprocess to end.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
case <-sigC:
// TODO: maybe we should set a timeout while waiting for the subprocess
gs.Logger.Debug("Signal received. Waiting for subprocess to end.")
case sig := <-sigC:
gs.Logger.WithField("signal", sig.String()).Debug("Signal received, waiting for the subprocess to handle it and return.")

}
gs.OSExit(rc)
case <-sigC:
// TODO: maybe we should set a timeout while waiting for the subprocess
Copy link
Contributor

@codebien codebien Apr 29, 2025

Choose a reason for hiding this comment

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

Suggested change
// TODO: maybe we should set a timeout while waiting for the subprocess

I want to centralize this logic to k6 as much as possible, so the signal handling should be fully delegated to k6.

Except if we see a good reason to force the exit here.

Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
@codebien codebien merged commit bdfea21 into feat/binary-provisioning Apr 29, 2025
28 checks passed
@codebien codebien deleted the binary-provisioning/handle-signals branch April 29, 2025 14:19
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.

3 participants