Skip to content

The opencloud CLI catches SIGINT, SIGTERM, SIGQUIT and SIGHUP for the whole run of a command #4041

Open

Description

@pbleser-oc

Describe the bug

The root command creates its context with signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) and never calls the returned stop function (opencloud/pkg/command/root.go, Execute). The handlers stay installed as long as the process runs. For the commands an admin runs by hand or from cron, that has two effects:

  1. nohup doesn't protect a command from SIGHUP. nohup starts the process with SIGHUP ignored, but signal.Notify installs a handler for an ignored SIGHUP anyway (see the documentation of os/signal). When the terminal session ends, the command's context is cancelled. storage-users revisions cleanup, for example, then stops with "interrupted" and exit code 1.
  2. SIGQUIT no longer dumps the goroutines. Go's default for SIGQUIT is to print the stacks of all goroutines and exit, which helps to see where a hanging command is stuck. Here it only cancels the context, like Ctrl-C.

Steps to reproduce

  1. Run a long-running command with nohup, e.g. nohup opencloud storage-users revisions cleanup --all --dry-run > cleanup.log &.
  2. Close the terminal session, or send the process a SIGHUP.

Expected behavior

The command keeps running, as nohup promises.

Actual behavior

The command stops: The cleanup was interrupted, before all files were cleaned up., exit code 1.

Suggestion

  • Don't listen to SIGHUP when it is ignored (signal.Ignored(syscall.SIGHUP)), so that nohup works.
  • Consider leaving SIGQUIT to Go's default handler.

Setup

opencloud main, single binary, posix driver. Every command under the root command is affected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions