Skip to content

fix(go): close the last signal.Notify path in the test OCI server - #463

Merged
manusa merged 2 commits into
mainfrom
fix/signal-handling-followups
Nov 21, 2026
Merged

manusa merged 2 commits into
mainfrom
fix/signal-handling-followups

Conversation

@manusa

@manusa manusa commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Follow-ups from the review of #411, which stopped the native library from replacing the host JVM's signal handlers during install.

Relates to #409

Changes

  • install.go comment and client.Run. The comment now explains why signal.Notify is deliberately not used: in a c-shared library it takes over the JVM's SIGINT/SIGTERM/SIGQUIT handlers for good, so shutdown hooks never run and kill -3 thread dumps stop working. It also states the trade-off: a signal no longer cancels an in-flight install, and the release can be left pending-install. It references Go runtime signal handlers permanently replace the host JVM's SIGINT/SIGTERM handlers after install #409, fix(go): stop replacing host process signal handlers during install #411, fix: prevent segmentation faults when performing helm install #113 and Segmentation faults and other native errors running helm-java with async-profiler #112. client.Run(...) replaces RunWithContext(context.Background(), ...), which is the same call in helm v3.22.1.
  • Last signal.Notify path closed. RepoOciServerStart no longer sets config.HTTP.DrainTimeout. With a non-zero value, distribution's Registry.ListenAndServe registers signal.Notify(..., os.Interrupt, syscall.SIGTERM). With 0 it serves directly (distribution v3.1.2 registry/registry.go:325-330). So a JVM that starts the test OCI registry (HelmPushTest, HelmRegistryTest, HelmShowTest, or a downstream test) keeps its handlers. Nothing else linked into the library reaches signal.Notify.
  • HelmSignalHandlerTest hardened.
    • A class-level @Timeout(2 min, SEPARATE_THREAD) bounds each test.
    • The child's output goes to a file in a @TempDir and appears in every assertion description. A file is needed because Process.destroy() closes the pipes, which would lose the output written after SIGTERM.
    • The native library extraction and Go's TMPDIR also go to the @TempDir, so nothing is left behind even if the child has to be killed.
    • The probe registers a shutdown hook, and the test asserts that its marker appears and that the exit code is 143.
    • There are three cases, so a failure shows which entry point regressed: install, template, and starting the test OCI server. The OCI case waits for an HTTP response, which proves that any signal handlers are already registered.
  • Two audit fixes.
    • NativeLibraryTest now clears the com.marcnuri.jkube-helm.forceUpdate system property, which leaked to later tests.
    • TestSearchRepo creates its repositories file in t.TempDir() instead of leaving it in the system temp directory.

Testing

On Java 8 (linux/amd64):

  • make build-native, gofmt -l, go vet and git diff --check are clean.
  • HelmSignalHandlerTest passes 3/3, repeated over several runs at about 1–6 s per case.
  • HelmPushTest, HelmRegistryTest, HelmShowTest, the lib/api tests, and the Go tests that use the OCI server (TestPush*, TestRegistryLogin*, TestRegistryLogout) all pass, as do the install/template/upgrade Go tests and TestSearchRepo.

Fail-without-fix checks, each against a rebuilt native library:

manusa and others added 2 commits November 21, 2026 11:26
Follow-ups from the review of #411:
- RepoOciServerStart no longer sets an HTTP drain timeout, which made
  distribution's Registry.ListenAndServe call signal.Notify and take
  over the host JVM's SIGINT/SIGTERM handlers
- install.go explains why signal.Notify is not used and the trade-off
  (a signal no longer cancels an in-flight install); use client.Run
- HelmSignalHandlerTest is bounded by a timeout, keeps the child's
  output, uses @tempdir, asserts that shutdown hooks run, and covers
  install, template and the test OCI server
- NativeLibraryTest clears the forceUpdate system property, and
  TestSearchRepo creates its repositories file in t.TempDir()

Relates to #409

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Marc Nuri <marc@marcnuri.com>
Both swallowed setup errors, so a failure surfaced later as an
unrelated assertion (an empty search result, or a ConnectException
after 30 s) instead of its cause:
- TestSearchRepo fails on a RepoAdd error, and uses a path in
  t.TempDir() instead of an unchecked temp file (RepoAdd creates it)
- the signal test's OCI probe throws with the native error when the
  test OCI server fails to start

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Marc Nuri <marc@marcnuri.com>

@manusa manusa left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Review of #463

Verdict: approve. This is a comment rather than an approval only because it's my own PR. There are no Critical or Important findings. The two minor suggestions from the review of 4c107a8 are already addressed in 940c556.

This PR delivers every suggestion from the #411 review:

  1. The install.go comment is accurate and names SIGQUIT.
  2. DrainTimeout is removed.
  3. The signal test has a timeout and keeps the child's output.
  4. It uses @TempDir.
  5. It asserts the shutdown hook and covers template.

The description matches the diff.

Correctness

  • DrainTimeout removal. distribution v3.1.2 (native/go.mod) returns server.Serve(ln) when DrainTimeout == 0 (registry/registry.go:325-327), before the signal.Notify at :330.
    • Nothing relied on the drain: it only runs after a signal, serverStop never stops OCI servers, and nothing calls Shutdown or helm's repotest.NewOCIServer.
    • Nothing else linked into the library reaches signal.Notify. The kubectl interrupt and term helpers are linked, but nothing calls them.
  • install.go. In helm v3.22.1, Install.Run is RunWithContext(context.Background(), …). The comment's trade-off is accurate:
    • failRelease marks the release failed, or uninstalls it with Atomic;
    • pending-install is set before the run;
    • upgrade never had signal cancellation.

HelmSignalHandlerTest

  • Black-box behaviour. It asserts exit code 143 and the shutdown-hook marker. The OCI case uses HelmLibHolder.INSTANCE to start the test registry, as HelmRegistryTest, HelmPushTest and HelmShowTest already do, since no public API exists for it.
  • Timing and cleanup. The timing fits within the 2-minute @Timeout. The child is destroyed before the @TempDir is cleaned up, and the native library extraction and Go's TMPDIR both land in the @TempDir.
  • Each case fails on its own when its bug returns:
    • with the pre-#411 signal.Notify back in install(), only the install and template cases fail;
    • with DrainTimeout = 1s back, only the OCI case fails.
  • CI. It runs on Linux and macOS: 3/3 on macOS in 10.9 s. Windows is skipped by design.

Addressed in 940c556

  • TestSearchRepo now uses a path in t.TempDir(), which RepoAdd creates, and fails on a RepoAdd error instead of reporting a confusing search failure.
  • The signal test's OCI probe throws with the native error when the test OCI server fails to start, instead of hitting an unrelated ConnectException 30 s later.

Follow-up, tracked separately

The other Go RepoAdd tests still create their file with os.CreateTemp("", …), which leaves /tmp/repositories.lock behind. They, and the Java tests, also write to the developer's real ~/.cache/helm. Test isolation is handled in a separate PR.

@manusa
manusa merged commit 039809a into main Nov 21, 2026
3 checks passed
@manusa
manusa deleted the fix/signal-handling-followups branch November 21, 2026 17:29
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.

1 participant