Skip to content

feat(exec): Add support for interrupting exec using signal #1469

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Fgerthoffert
Copy link

@Fgerthoffert Fgerthoffert commented Jul 17, 2023

GitHub actions document the use of timeout_minutes at a step level when writing composite action.

When creating js/ts actions, it's currently not possible to implement a timeout mechanism within only a portion of an action.

This PR adds support for "AbortSignal" as per the available option in child.spawn.

Our use case is fairly straightforward, we built a GitHub action performing the following:

  • provisioning an environment,
  • executing integration tests,
  • collecting run artifacts.

We want to introduce the ability to interrupt the integration tests if they are taking longer than usual. But even if the tests are interrupted, we still want to execute the rest of the action (and collect the artifacts).

The following code stops the execution of the exec call if it takes more than 5s:

try {
  core.info(`Command starting at: ${JSON.stringify(new Date())}`)
  await exec.exec("sleep 10000", [], {signal: AbortSignal.timeout(5000)})
  core.info(`Command completed at: ${JSON.stringify(new Date())}`)
} catch (error: any) {
  if (error.name === "AbortError") {
    core.info(`Timeout reached at: ${JSON.stringify(new Date())}. The command was interrupted`)
  } else {
    core.info(`There was an issue processing the command (${error.name}). It failed at: ${JSON.stringify(new Date())}`)
  }
}

@Fgerthoffert Fgerthoffert requested a review from a team as a code owner July 17, 2023 22:21
@Fgerthoffert Fgerthoffert changed the title feat(exec): Added support for interrupting exec using signal feat(exec): Add support for interrupting exec using signal Jul 17, 2023
@Fgerthoffert
Copy link
Author

Hello,

any chance of having this PR reviewed and integrated in an upcoming release ?

Thanks,

@Fgerthoffert
Copy link
Author

Hi,

Sorry to bother but it would be great if this PR could be reviewed.

Thanks much.

@Fgerthoffert
Copy link
Author

Hi,

Is there any chance of getting this PR reviewed? I'm happy to provide more details if the description is unclear.

I want to avoid forking for such a trivial change.

Thanks,

@Fgerthoffert
Copy link
Author

We're still hoping for this PR to get some attention/review, not being able to interrupt an exec() in Typescript actions is a pain if the said action must perform other tasks after a potential timeout.

@franky47
Copy link

franky47 commented Apr 9, 2024

This would come in handy in my action (47ng/actions-clever-cloud) to allow cancelling the Promise associated with a timed-out deployment.

@Fgerthoffert
Copy link
Author

This is still an open topic on our side, a review / merge would be greatly appreciated.

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.

2 participants