Fix Pre-step hang on agent API timeout + guard against unhandled reje…#673
Open
varunsh-coder wants to merge 4 commits into
Open
Fix Pre-step hang on agent API timeout + guard against unhandled reje…#673varunsh-coder wants to merge 4 commits into
varunsh-coder wants to merge 4 commits into
Conversation
…ctions - Replace @actions/http-client socketTimeout with fetch + AbortSignal.timeout(3s) on monitor, tls-inspect, policy fetch, policy-store fetch, and addSummary, so DNS + TCP connect + TLS are bounded (was unbounded, causing ~2-4 min hangs) - Add unhandledRejection guard in setup.ts and cleanup.ts so Node 22+ does not silently kill the step on background async errors from third-party deps - Skip Windows post-step cleanup when agent dir is missing (Pre-step crashed before install), instead of throwing ENOENT on post_event.json - Bump @types/node to ^24, typescript to ^5, ts-jest to ^29.4 to match node24 runtime and enable AbortSignal.timeout typings
There was a problem hiding this comment.
Pull request overview
This PR hardens the GitHub Action’s pre/post steps against long hangs and silent termination by bounding network calls (DNS/TCP/TLS included) and adding runtime guards for unhandled promise rejections in newer Node runtimes.
Changes:
- Replace
@actions/http-clientsocket timeouts withfetch()+AbortSignal.timeout(3000)for monitor/TLS/policy/policy-store/summary calls to avoid multi-minute hangs. - Add
process.on("unhandledRejection")guards in pre-step (setup.ts) and post-step (cleanup.ts) to prevent Node 22+ from terminating the step on background async errors. - Skip Windows post-step cleanup when the agent directory is missing (e.g., pre-step failed before installation), and update tooling versions for Node 24/TS5.
Reviewed changes
Copilot reviewed 8 out of 15 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/tls-inspect.ts | Switch TLS status check to fetch() with an abort timeout and simplified return flow. |
| src/tls-inspect.test.ts | Replace nock with fetch mocking; add timeout/hang regression tests. |
| src/setup.ts | Add unhandled-rejection guard; replace monitor API call with fetch() + abort timeout. |
| src/policy-utils.ts | Replace policy fetches with fetch() + abort timeout and add HTTP status error handling. |
| src/policy-utils.test.ts | Replace nock with fetch mocking; add retry/status/timeout regression tests. |
| src/common.ts | Bound job summary fetch with AbortSignal.timeout(3000). |
| src/cleanup.ts | Add unhandled-rejection guard and skip Windows cleanup when agent directory is missing. |
| package.json | Update dev tooling versions for Node 24 / TS5 compatibility. |
| package-lock.json | Lockfile updates reflecting the dev dependency bumps. |
| dist/pre/index.js | Compiled bundle updates reflecting source changes. |
| dist/post/index.js | Compiled bundle updates reflecting source changes. |
| dist/index.js | Compiled bundle updates reflecting source changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
37
to
40
| err = e; | ||
| } | ||
| retry += 1; | ||
| await sleep(1000); | ||
| } |
Comment on lines
+83
to
87
| } | ||
| err = e; | ||
| } | ||
| retry += 1; | ||
| await sleep(1000); | ||
| } |
Comment on lines
+54
to
+56
| process.on("unhandledRejection", (reason) => { | ||
| core.warning(`Unhandled promise rejection during Pre-step: ${reason}`); | ||
| }); |
Comment on lines
+12
to
+15
| // See setup.ts for rationale — Node 22+ kills the process on unhandled rejections. | ||
| process.on("unhandledRejection", (reason) => { | ||
| core.warning(`Unhandled promise rejection during Post-step: ${reason}`); | ||
| }); |
Comment on lines
+58
to
+60
| expect(result).toBe(false); | ||
| expect(elapsed).toBeLessThan(3500); | ||
| expect(elapsed).toBeGreaterThanOrEqual(2800); |
Comment on lines
17
to
+19
| } catch (e) { | ||
| core.info(`[!] Unable to check TLS_STATUS`); | ||
| return false; |
Comment on lines
+113
to
+117
| if (!resp.ok) { | ||
| throw new HttpStatusError(resp.status, `HTTP ${resp.status}`); | ||
| } | ||
| return (await resp.json()) as T; | ||
| } |
Comment on lines
46
to
+49
| "jest": "^29.3.1", | ||
| "jest-junit": ">=13.0.0", | ||
| "nock": "^13.3.0", | ||
| "ts-jest": "^29.0.3", | ||
| "ts-jest": "^29.4.11", |
handleLinuxCleanup and handleMacosCleanup also did an unconditional writeFileSync to a path inside the agent dir, throwing ENOENT when Pre-step crashed before installing the agent (proven by integration test on synthetic-reject branch). Mirror the same dir-existence check that handleWindowsCleanup already has.
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.
…ctions