Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/orb/broker-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export async function drainOrbRelay(
method: "POST",
headers: { authorization: `Bearer ${env.ORB_ENROLLMENT_SECRET}`, "content-type": "application/json" },
body: JSON.stringify({ ack }),
signal: AbortSignal.timeout(15_000),
signal: AbortSignal.timeout(30_000),
});
if (!res.ok) throw new Error(`orb_relay_drain_http_${res.status}`);
const body = (await res.json()) as { events?: Array<{ deliveryId?: unknown; eventName?: unknown; rawBody?: unknown }> };
Expand Down
31 changes: 20 additions & 11 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1007,25 +1007,34 @@ async function main(): Promise<void> {
const { drainOrbRelay } = await import("./orb/broker-client");
const { enqueueWebhookByEnv } = await import("./github/webhook");
/* v8 ignore start -- pull-mode relay loop is a live self-host timer; monitor semantics are covered in selfhost tests. */
let drainInFlight = false;
const drainRelay = async (): Promise<void> => {
await drainOrbRelayWithMonitor({
state: relayDrainState,
relayEnv: {
ORB_ENROLLMENT_SECRET: process.env.ORB_ENROLLMENT_SECRET,
ORB_BROKER_URL: process.env.ORB_BROKER_URL,
},
env,
drain: drainOrbRelay,
enqueue: enqueueWebhookByEnv,
});
if (drainInFlight) return;
drainInFlight = true;
try {
await drainOrbRelayWithMonitor({
state: relayDrainState,
relayEnv: {
ORB_ENROLLMENT_SECRET: process.env.ORB_ENROLLMENT_SECRET,
ORB_BROKER_URL: process.env.ORB_BROKER_URL,
},
env,
drain: drainOrbRelay,
enqueue: enqueueWebhookByEnv,
});
} finally {
drainInFlight = false;
}
};
void drainRelay();
// 30s matches broker-client's request timeout so a slow/degraded broker's in-flight drain has fully
// timed out (or completed) before the next tick would otherwise pile another request on top of it.
setInterval(
() =>
void drainRelay().catch((error) =>
captureError(error, { kind: "orb_relay_drain" }),
),
15_000,
30_000,
);
/* v8 ignore stop */
}
Expand Down
Loading