Skip to content

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

TypeScript

fix(rpc-proxy): distinguish disconnect timeout (504) from unreachable (502) (R1-L1)

Diego Zacariasf729bb529775
diff --git a/external-rest-api/src/releaseManifest.ts b/external-rest-api/src/releaseManifest.ts
index f1cda4b96..5bf3423ed 100644
--- a/external-rest-api/src/releaseManifest.ts
+++ b/external-rest-api/src/releaseManifest.ts
@@ -9,7 +9,7 @@ export type ReleaseManifest = {
export const releaseManifest: ReleaseManifest = {
releaseId: 'v0.7.0',
externalRestApiVersion: '0.1.81',
- rpcProxyVersion: '0.1.69',
+ rpcProxyVersion: '0.1.70',
desktopVersion: '0.7.0',
minimumDesktopVersion: '0.1.252',
}
diff --git a/rpc-proxy/package-lock.json b/rpc-proxy/package-lock.json
index c6e06d9b8..394884333 100644
--- a/rpc-proxy/package-lock.json
+++ b/rpc-proxy/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-rpc-proxy",
- "version": "0.1.69",
+ "version": "0.1.70",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-rpc-proxy",
- "version": "0.1.69",
+ "version": "0.1.70",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.21.2",
diff --git a/rpc-proxy/package.json b/rpc-proxy/package.json
index 53ef788c9..0d68e267d 100644
--- a/rpc-proxy/package.json
+++ b/rpc-proxy/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-rpc-proxy",
- "version": "0.1.69",
+ "version": "0.1.70",
"description": "External-facing RPC proxy for tenant-scoped MCP access",
"main": "dist/main.js",
"engines": {
diff --git a/rpc-proxy/src/routes/mcpOauth.ts b/rpc-proxy/src/routes/mcpOauth.ts
index 1498610a8..34ab47d0e 100644
--- a/rpc-proxy/src/routes/mcpOauth.ts
+++ b/rpc-proxy/src/routes/mcpOauth.ts
@@ -172,7 +172,23 @@ export function createMcpOauthRouter(): Router {
}),
signal: AbortSignal.timeout(config.upstreamTimeoutMs),
})
- } catch {
+ } catch (err) {
+ // Distinguish a timeout from a genuine connect failure. `AbortSignal.
+ // timeout()` rejects fetch with a `TimeoutError`; a manual abort would
+ // be `AbortError`. A timeout means control-api was reachable but slow →
+ // 504 (gateway timeout); anything else → 502 (unreachable). Bind + log
+ // the error either way (it was silently swallowed before).
+ const name = err instanceof Error ? err.name : ''
+ if (name === 'TimeoutError' || name === 'AbortError') {
+ console.warn(`[RPC_PROXY] control-api disconnect timed out server=${mcpServerName}`)
+ res.status(504).json({ error: 'control_api_timeout' })
+ return
+ }
+ console.warn(
+ `[RPC_PROXY] control-api disconnect fetch failed server=${mcpServerName} error=${
+ err instanceof Error ? err.message : String(err)
+ }`
+ )
res.status(502).json({ error: 'control_api_unreachable' })
return
}
diff --git a/rpc-proxy/src/routes/mcpOauthDisconnect.test.ts b/rpc-proxy/src/routes/mcpOauthDisconnect.test.ts
index c3f65ec9e..b3133684f 100644
--- a/rpc-proxy/src/routes/mcpOauthDisconnect.test.ts
+++ b/rpc-proxy/src/routes/mcpOauthDisconnect.test.ts
@@ -137,4 +137,28 @@ describe('DELETE /api/v1/mcp-oauth/:mcpServerName/grant (spec 11 U4 disconnect)'
expect(res.status).toBe(502)
expect(res.body.error).toBe('control_api_unreachable')
})
+
+ it('returns 504 (not 502) when the control-api call times out, and logs it (R1-L1)', async () => {
+ const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
+ // AbortSignal.timeout() rejects fetch with a TimeoutError.
+ fetchSpy.mockRejectedValue(
+ Object.assign(new Error('The operation timed out'), {
+ name: 'TimeoutError',
+ })
+ )
+ const res = await request(makeApp()).delete(PATH).set('Authorization', 'Bearer t').send({})
+ expect(res.status).toBe(504)
+ expect(res.body.error).toBe('control_api_timeout')
+ expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('[RPC_PROXY]'))
+ warnSpy.mockRestore()
+ })
+
+ it('also treats a manual AbortError as a 504 timeout (R1-L1)', async () => {
+ const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
+ fetchSpy.mockRejectedValue(Object.assign(new Error('aborted'), { name: 'AbortError' }))
+ const res = await request(makeApp()).delete(PATH).set('Authorization', 'Bearer t').send({})
+ expect(res.status).toBe(504)
+ expect(res.body.error).toBe('control_api_timeout')
+ warnSpy.mockRestore()
+ })
})