mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-29 19:01:44 +00:00
fix(regression): fail discord startup on reconnect exhaustion
This commit is contained in:
@@ -855,6 +855,37 @@ describe("runDiscordGatewayLifecycle", () => {
|
||||
expect(runtimeError).toHaveBeenCalledWith(expect.stringContaining("Max reconnect attempts"));
|
||||
});
|
||||
|
||||
it("rejects reconnect-exhausted queued before startup when shutdown has not begun", async () => {
|
||||
const { runDiscordGatewayLifecycle } = await import("./provider.lifecycle.js");
|
||||
const pendingGatewayEvents: DiscordGatewayEvent[] = [];
|
||||
|
||||
const emitter = new EventEmitter();
|
||||
const gateway: MockGateway = {
|
||||
isConnected: true,
|
||||
options: { intents: 0, reconnect: { maxAttempts: 50 } } as GatewayPlugin["options"],
|
||||
disconnect: vi.fn(),
|
||||
connect: vi.fn(),
|
||||
emitter,
|
||||
};
|
||||
getDiscordGatewayEmitterMock.mockReturnValueOnce(emitter);
|
||||
|
||||
const { lifecycleParams } = createLifecycleHarness({
|
||||
gateway,
|
||||
pendingGatewayEvents,
|
||||
});
|
||||
|
||||
pendingGatewayEvents.push(
|
||||
createGatewayEvent(
|
||||
"reconnect-exhausted",
|
||||
"Max reconnect attempts (0) reached after code 1005",
|
||||
),
|
||||
);
|
||||
|
||||
await expect(runDiscordGatewayLifecycle(lifecycleParams)).rejects.toThrow(
|
||||
"Max reconnect attempts",
|
||||
);
|
||||
});
|
||||
|
||||
it("does not push connected: true when abortSignal is already aborted", async () => {
|
||||
const { runDiscordGatewayLifecycle } = await import("./provider.lifecycle.js");
|
||||
const emitter = new EventEmitter();
|
||||
|
||||
@@ -83,9 +83,13 @@ export async function runDiscordGatewayLifecycle(params: {
|
||||
return "continue";
|
||||
}
|
||||
// Don't throw for expected shutdown events. `reconnect-exhausted` can be
|
||||
// queued before teardown flips `lifecycleStopping`, so treat it as a
|
||||
// graceful stop here and let the health monitor own reconnect behavior.
|
||||
if (event.type === "disallowed-intents" || event.type === "reconnect-exhausted") {
|
||||
// queued just before an abort-driven shutdown flips `lifecycleStopping`,
|
||||
// so only suppress it when shutdown is already underway.
|
||||
if (
|
||||
event.type === "disallowed-intents" ||
|
||||
(event.type === "reconnect-exhausted" &&
|
||||
(lifecycleStopping || params.abortSignal?.aborted === true))
|
||||
) {
|
||||
return "stop";
|
||||
}
|
||||
throw event.err;
|
||||
|
||||
Reference in New Issue
Block a user