fix: prevent EC2 termination when GitHub runner de-registration fails#5064
Closed
shivdesh wants to merge 1 commit intogithub-aws-runners:mainfrom
Closed
fix: prevent EC2 termination when GitHub runner de-registration fails#5064shivdesh wants to merge 1 commit intogithub-aws-runners:mainfrom
shivdesh wants to merge 1 commit intogithub-aws-runners:mainfrom
Conversation
When the scale-down Lambda fails to de-register a runner from GitHub (even after automatic retries via @octokit/plugin-retry), the EC2 instance should NOT be terminated. This prevents stale runner entries in GitHub org settings. This change complements PR github-aws-runners#4990 which added @octokit/plugin-retry for automatic retries. While that handles transient failures, this ensures that if de-registration ultimately fails, we don't leave orphaned GitHub runner entries by terminating the EC2 instance prematurely. Key changes: - Extract deleteGitHubRunner() helper that catches errors per-runner - Only terminate EC2 instance if ALL GitHub de-registrations succeed - If any de-registration fails, leave instance running for next cycle The @octokit/plugin-retry (added in github-aws-runners#4990) handles automatic retries at the client level, so no custom retry logic is needed here. Tests: - Add test verifying EC2 is NOT terminated when de-registration fails
Author
|
Closing in favor of updating PR #5061 with the same simplified approach. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR complements #4990 by ensuring that when GitHub runner de-registration fails (even after automatic retries), the EC2 instance is not terminated. This prevents stale runner entries in GitHub org settings.
Problem
When the scale-down Lambda fails to de-register a runner from GitHub (e.g., due to persistent API errors), the current code still terminates the EC2 instance. This leaves stale/offline runner entries in the GitHub organization settings.
We encountered this issue in production where transient 502 errors during scale-down left 117 stale runner entries in our GitHub organization.
Relationship to #4990
PR #4990 added
@octokit/plugin-retrywhich provides automatic retries at the Octokit client level. This is great for handling transient failures. However, if de-registration ultimately fails after all retries, we still need to handle that gracefully by NOT terminating the EC2 instance.Solution
deleteGitHubRunner()helper that catches errors per-runnerChanges
lambdas/functions/control-plane/src/scale-runners/scale-down.ts:deleteGitHubRunner()helper functionremoveRunner()to only terminate EC2 if all de-registrations succeedTesting
Why not custom retry logic?
The
@octokit/plugin-retry(added in #4990) already handles automatic retries at the client level, so no custom retry logic is needed. This PR focuses solely on the failure handling aspect - what to do when de-registration fails after all retries.