Skip to content

Fix Pre-step hang on agent API timeout + guard against unhandled reje…#673

Open
varunsh-coder wants to merge 4 commits into
mainfrom
fix/aggregate-error-startup-hang
Open

Fix Pre-step hang on agent API timeout + guard against unhandled reje…#673
varunsh-coder wants to merge 4 commits into
mainfrom
fix/aggregate-error-startup-hang

Conversation

@varunsh-coder

Copy link
Copy Markdown
Member

…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

…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
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

Test Results

70 tests  +3   70 ✅ +3   43s ⏱️ +9s
 7 suites ±0    0 💤 ±0 
 1 files   ±0    0 ❌ ±0 

Results for commit 774f75f. ± Comparison against base commit 9af89fc.

♻️ This comment has been updated with latest results.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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-client socket timeouts with fetch() + 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 thread src/policy-utils.ts
Comment on lines 37 to 40
err = e;
}
retry += 1;
await sleep(1000);
}
Comment thread src/policy-utils.ts
Comment on lines +83 to 87
}
err = e;
}
retry += 1;
await sleep(1000);
}
Comment thread src/setup.ts
Comment on lines +54 to +56
process.on("unhandledRejection", (reason) => {
core.warning(`Unhandled promise rejection during Pre-step: ${reason}`);
});
Comment thread src/cleanup.ts
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 thread src/tls-inspect.test.ts Outdated
Comment on lines +58 to +60
expect(result).toBe(false);
expect(elapsed).toBeLessThan(3500);
expect(elapsed).toBeGreaterThanOrEqual(2800);

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 15 changed files in this pull request and generated 3 comments.

Comment thread src/tls-inspect.ts
Comment on lines 17 to +19
} catch (e) {
core.info(`[!] Unable to check TLS_STATUS`);
return false;
Comment thread src/policy-utils.ts
Comment on lines +113 to +117
if (!resp.ok) {
throw new HttpStatusError(resp.status, `HTTP ${resp.status}`);
}
return (await resp.json()) as T;
}
Comment thread package.json
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.
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