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

explicitly handle SIGINT and SIGTERM #1448

Conversation

joelanford
Copy link
Member

@joelanford joelanford commented Sep 10, 2024

Description of the change:

This PR adds explicit handling for SIGINT and SIGTERM, so that we can catch those signals and propagate them via a Go context to long running processes in order to perform a graceful shutdown.

Motivation for the change:

Temporary files are being left behind because defer statements are not executed when these signals are not caught and handled by the program. This PR ensures that we run defer statements prior to exiting.

Reviewer Checklist

  • Implementation matches the proposed design, or proposal is updated to match implementation
  • Sufficient unit test coverage
  • Sufficient end-to-end test coverage
  • Docs updated or added to /docs
  • Commit messages sensible and descriptive

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 10, 2024
Copy link
Contributor

openshift-ci bot commented Sep 10, 2024

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 10, 2024
Copy link

codecov bot commented Sep 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 48.53%. Comparing base (1f9e725) to head (6a917e9).
Report is 15 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1448      +/-   ##
==========================================
+ Coverage   48.47%   48.53%   +0.05%     
==========================================
  Files         136      135       -1     
  Lines       12814    12800      -14     
==========================================
  Hits         6212     6212              
+ Misses       5561     5547      -14     
  Partials     1041     1041              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@joelanford joelanford force-pushed the explicit-signal-handling branch 2 times, most recently from 7be452f to fdefe60 Compare September 11, 2024 18:05
@joelanford joelanford marked this pull request as ready for review September 11, 2024 21:10
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 11, 2024
Copy link
Contributor

@perdasilva perdasilva left a comment

Choose a reason for hiding this comment

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

If I understand the changes correctly, we are now using the signal package to create a top context that will cancel on SIGINT or SIGTERM. This context is set as the cmd context, and each (long running) opm command creates a sub-context (with the top level context as parent) for its work. These commands also spawn a go routine to monitor the context and shutdown gracefully if it gets cancelled. Therefore, if the command's context gets cancelled -> graceful shutdown, if the process gets a SIGINT or SIGTERM, the top level process gets cancelled and propagates down to the sub-contexts -> graceful shutdown.

We're getting a breaking api change by deleting shutdown.go - but that should be ok as this package is only really meaningful for the command structure (as opposed to manipulating catalog content). So, lgtm ^^

Copy link
Contributor

openshift-ci bot commented Sep 12, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: joelanford, perdasilva

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [joelanford,perdasilva]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@grokspawn
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Sep 14, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit 66733c7 into operator-framework:master Sep 14, 2024
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants