Compare commits

...
2 changed files with 30 additions and 0 deletions
@@ -1786,6 +1786,8 @@ export class DaemonClientCore {
// An endpoint security policy close cannot be fixed by retrying.
const securityFailure = describeEndpointSecurityClose(event);
if (securityFailure) this.setReconnectEnabled(false);
// A transport error may already have scheduled this socket's retry before its close.
if (this.reconnectTimeout && !securityFailure && !this.authFailureReasonValue) return;
const reason = this.authFailureReasonValue
? new DaemonAuthenticationError(this.authFailureReasonValue).message
: (securityFailure ?? describeTransportClose(event));
+28
View File
@@ -3020,6 +3020,34 @@ test("foreground keeps a connect attempt that just started", async () => {
expect(client.getConnectionState().status).toBe("connected");
});
test("a handshake error followed by a close consumes one reconnect attempt", async () => {
useHeartbeatClock();
const [first, failed, recovered] = [
new FakeDaemon(),
new FakeDaemon(),
new FakeDaemon(),
] as const;
const { client, attempts } = connectThroughReplacements("error-and-close", [
first,
failed,
recovered,
]);
const connection = client.connect();
first.openConnection();
await connection;
first.daemonClosesWith("connection lost");
await vi.advanceTimersByTimeAsync(1_500);
expect(attempts()).toBe(2);
failed.triggerError(new Error("read ECONNRESET"));
failed.daemonClosesWith("abnormal closure");
await vi.advanceTimersByTimeAsync(2_999);
expect(attempts()).toBe(2);
await vi.advanceTimersByTimeAsync(1);
expect(attempts()).toBe(3);
recovered.openConnection();
expect(client.getConnectionState().status).toBe("connected");
});
test("foreground resets the retry delay after failed connections in the background", async () => {
useHeartbeatClock();
const daemons = Array.from({ length: 7 }, () => new FakeDaemon());