Skip to content
Closed
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
26 changes: 26 additions & 0 deletions apps/desktop/src/backend/DesktopLocalEnvironmentAuth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,30 @@ describe("DesktopLocalEnvironmentAuth", () => {
assert.strictEqual(yield* Ref.get(requestCount), 1);
}).pipe(Effect.provide(TestClock.layer())),
);

it.effect("waits out a backend that stays unresponsive for 30 seconds after launch", () =>
Effect.gen(function* () {
// A stopped backend accepts connections but answers nothing until resumed.
const resumed = yield* Deferred.make<void>();
const layerHttpClient = Layer.succeed(
HttpClient.HttpClient,
HttpClient.make((request) =>
Deferred.await(resumed).pipe(Effect.as(tokenResponse(request))),
),
);
const auth = yield* DesktopLocalEnvironmentAuth.DesktopLocalEnvironmentAuth.pipe(
Effect.provide(
DesktopLocalEnvironmentAuth.layer.pipe(
Layer.provide(Layer.mergeAll(layerPool, layerHttpClient, NodeCrypto.layerMac)),
),
),
);

const fiber = yield* auth.getBearerToken.pipe(Effect.forkChild);
yield* TestClock.adjust(Duration.seconds(30));
yield* Deferred.succeed(resumed, undefined);

assert.strictEqual(yield* Fiber.join(fiber), "desktop-bearer-token");
}).pipe(Effect.provide(TestClock.layer())),
);
});
3 changes: 2 additions & 1 deletion apps/desktop/src/backend/DesktopLocalEnvironmentAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import * as HttpClient from "effect/http/HttpClient";

import * as DesktopBackendPool from "./DesktopBackendPool.ts";

const BOOTSTRAP_TRANSIENT_RETRY_TIMEOUT = Duration.seconds(15);
// A backend can stay unresponsive for ~30s after reporting ready.
const BOOTSTRAP_TRANSIENT_RETRY_TIMEOUT = Duration.seconds(60);
const BOOTSTRAP_TRANSIENT_RETRY_INTERVAL = Duration.millis(500);
const TRANSIENT_BOOTSTRAP_STATUS_CODES = new Set([502, 503, 504]);

Expand Down
Loading