Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(hcc): absorb rejected external-egress resync pass to avoid unhandledRejection [R4-A]

Alfredo Lopez5e2b075771f7
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index 894e839d9..60bbd9a99 100644
--- a/host-context-controller/package-lock.json
+++ b/host-context-controller/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-host-context-controller",
- "version": "0.1.218",
+ "version": "0.1.219",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.218",
+ "version": "0.1.219",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@clerum/image-policy": "file:../packages/image-policy",
diff --git a/host-context-controller/package.json b/host-context-controller/package.json
index 138dc09bc..2ce5af165 100644
--- a/host-context-controller/package.json
+++ b/host-context-controller/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-host-context-controller",
- "version": "0.1.218",
+ "version": "0.1.219",
"description": "Host Context Controller - provides McpServer CRDs to mcp-host via REST API",
"main": "dist/main.js",
"engines": {
diff --git a/host-context-controller/src/externalEgressConvergenceCoordinator.test.ts b/host-context-controller/src/externalEgressConvergenceCoordinator.test.ts
index 5fb6c7c41..bccee5997 100644
--- a/host-context-controller/src/externalEgressConvergenceCoordinator.test.ts
+++ b/host-context-controller/src/externalEgressConvergenceCoordinator.test.ts
@@ -877,4 +877,52 @@ describe('ExternalEgressConvergenceCoordinator', () => {
instance.stop()
})
+
+ it('logs and absorbs a rejected periodic resync pass, then re-arms (no unhandledRejection)', async () => {
+ vi.useFakeTimers()
+ vi.spyOn(Math, 'random').mockReturnValue(0)
+ const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => undefined)
+ // Capture any process-level unhandledRejection: the pre-fix code left the
+ // rejected `void runResync()` promise unhandled, which crashes modern Node.
+ const unhandled: unknown[] = []
+ const onUnhandled = (reason: unknown): void => {
+ unhandled.push(reason)
+ }
+ process.on('unhandledRejection', onUnhandled)
+
+ const selected = server('web-search')
+ // Reject OUTSIDE the per-server try/catch in runResyncCore (that catch only
+ // wraps the mutation). A rejecting `enqueue` propagates through the worker to
+ // Promise.all -> runResyncCore -> runResync, so the whole pass rejects.
+ const enqueue = vi.fn(async () => {
+ throw new Error('resync enqueue boom')
+ })
+ const { instance, servers } = coordinator({ enqueue })
+ servers.set(selected.name, selected)
+
+ try {
+ instance.startPeriodicResync(10, 5)
+ // First pass fires at 10s and rejects.
+ await vi.advanceTimersByTimeAsync(10_000)
+ await flushMicrotasks()
+
+ // The rejection is logged by the fix's .catch (RED without it: no such log).
+ expect(errorSpy).toHaveBeenCalledWith(
+ '[K8s] External egress periodic resync pass failed:',
+ expect.any(Error)
+ )
+ expect(enqueue).toHaveBeenCalledTimes(1)
+
+ // The loop RE-ARMS despite the failure: the successor fires 10s later.
+ await vi.advanceTimersByTimeAsync(10_000)
+ await flushMicrotasks()
+ expect(enqueue).toHaveBeenCalledTimes(2)
+
+ // The fix handles the rejection, so nothing escaped as unhandled.
+ expect(unhandled).toEqual([])
+ } finally {
+ process.off('unhandledRejection', onUnhandled)
+ instance.stop()
+ }
+ })
})
diff --git a/host-context-controller/src/externalEgressConvergenceCoordinator.ts b/host-context-controller/src/externalEgressConvergenceCoordinator.ts
index fe95ef295..55d8ec7c2 100644
--- a/host-context-controller/src/externalEgressConvergenceCoordinator.ts
+++ b/host-context-controller/src/externalEgressConvergenceCoordinator.ts
@@ -157,7 +157,17 @@ export class ExternalEgressConvergenceCoordinator {
this.dependencies.externalEgressRefreshMinTtlMs()
)
this.resyncTimer = setTimeout(() => {
- void this.runResync().finally(scheduleNext)
+ // Re-arm FIRST (.finally) so a rejected pass still schedules its
+ // successor — the "re-arms after completion" property must survive a
+ // failure. Then .catch logs and absorbs the rejection so a rejecting
+ // pass (or a throwing scheduleNext) never becomes an unhandledRejection,
+ // which crashes the process on modern Node and would silently kill the
+ // periodic resync loop (reopening the #299 DNS-drift window).
+ void this.runResync()
+ .finally(scheduleNext)
+ .catch(error =>
+ console.error('[K8s] External egress periodic resync pass failed:', error)
+ )
}, delayMs)
this.resyncTimer.unref?.()
}