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

fix: Stop and finalize build on exec termination #332

Merged
merged 5 commits into from
Aug 22, 2019
Merged

Conversation

wwilsman
Copy link
Contributor

Purpose

When running percy exec with a command that causes the process to hang, terminating the process causes builds to get stuck in a receiving state due to the build never finalizing.

Approach

Add signal handlers for SIGHUP, SIGINT, and SIGTERM to stop and finalize the build.

Multiple signals are sometimes sent and cause the stop method to get called multiple times. This didn't seem to effect finalizing builds, but caused noisy output in the terminal. An instance property, exiting, is used to bail out of the stop method when it has already been called. This also prevents secondary events from exiting before the first event has finalized the build.

Other changes

I also corrected a check for percyEnabled which treated the property as a getter when it is actually a method. Fixing this also highlighted a test which actually tested the incorrect behavior. This test was updated to reflect the desired behavior, which is to not warn about a missing token when Percy is disabled.

This property is a function and not a getter. Without invoking it as a function,
it's value is always truthy.
When the process was terminated, all of the signal handlers were triggered
causing multiple logs to be outputted. Skipping stopping the agent once another
event has stopped it causes subsequent events to skip straight to exiting, and
never finalizes builds.

Exiting is tracked so that if it is already being handled, there is no need to
handle exiting again.
The previous test tested that PERCY_ENABLED _did not_ work. That is, it tested
that a warning was still thrown even though it was disabled.

That test has been corrected to assert that _nothing_ is thrown when disabled.
@wwilsman wwilsman requested a review from Robdel12 August 22, 2019 15:16
Copy link
Contributor

@Robdel12 Robdel12 left a comment

Choose a reason for hiding this comment

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

🏁 This is going to solve a lot of issues

@@ -22,7 +22,7 @@ export default class PercyCommand extends Command {
}

async run() {
if (this.percyEnabled && !this.percyTokenPresent()) {
if (this.percyEnabled() && !this.percyTokenPresent()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Great catch here 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch!

src/commands/exec.ts Outdated Show resolved Hide resolved
@wwilsman wwilsman changed the title Stop and finalize build on exec termination [fix] Stop and finalize build on exec termination Aug 22, 2019
@wwilsman wwilsman changed the title [fix] Stop and finalize build on exec termination fix: Stop and finalize build on exec termination Aug 22, 2019
@wwilsman wwilsman merged commit 2fd90b9 into master Aug 22, 2019
@delete-merged-branch delete-merged-branch bot deleted the ww/exec-cleanup branch August 22, 2019 15:45
djones pushed a commit that referenced this pull request Aug 22, 2019
## [0.10.1](v0.10.0...v0.10.1) (2019-08-22)

### Bug Fixes

* Stop and finalize build on exec termination ([#332](#332)) ([2fd90b9](2fd90b9))
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.

None yet

3 participants