diff --git a/packages/client/src/effect/service.ts b/packages/client/src/effect/service.ts index d0514e3b75a..db2d15e46e6 100644 --- a/packages/client/src/effect/service.ts +++ b/packages/client/src/effect/service.ts @@ -131,7 +131,9 @@ export const ensure = Effect.fn("service.ensure")(function* (options: EnsureOpti }).pipe( Effect.repeat({ until: Option.isSome, - schedule: Schedule.max([Schedule.spaced(timing.pollInterval), Schedule.recurs(timing.attempts)]), + // Probes run sequentially, so a slow probe stretches each iteration; bound the loop by wall clock + // like the Promise variant rather than by attempt count. + schedule: Schedule.spaced(timing.pollInterval).pipe(Schedule.upTo({ duration: timing.promiseTimeout })), }), Effect.ensuring(Effect.sync(() => contenders.forEach((contender) => contender.release()))), ) diff --git a/packages/client/src/service-timing.ts b/packages/client/src/service-timing.ts index 31a50c6b5d1..03db9f6cb2c 100644 --- a/packages/client/src/service-timing.ts +++ b/packages/client/src/service-timing.ts @@ -1,6 +1,5 @@ export type EnsureTiming = { readonly pollInterval: number - readonly attempts: number readonly requestTimeout: number readonly spawnDelay: number readonly maxSpawnDelay: number @@ -11,9 +10,11 @@ export type EnsureTiming = { const timings = new WeakMap() +// A freshly spawned service registers in ~250 ms, so the poll cadence is a large share of the +// time a client waits for it. Probes are sequential, so the wait between them only matters while +// the connection is refused; both variants give up after promiseTimeout of wall-clock time. export const defaultEnsureTiming: EnsureTiming = { - pollInterval: 100, - attempts: 1_200, + pollInterval: 25, requestTimeout: 2_000, spawnDelay: 5_000, maxSpawnDelay: 30_000, diff --git a/packages/client/test/fixture/service-timing.ts b/packages/client/test/fixture/service-timing.ts index f4db65ae1f5..8c9ff85e15a 100644 --- a/packages/client/test/fixture/service-timing.ts +++ b/packages/client/test/fixture/service-timing.ts @@ -2,7 +2,6 @@ import { withEnsureTiming } from "../../src/service-timing" const timing = { pollInterval: 20, - attempts: 120, requestTimeout: 100, spawnDelay: 200, maxSpawnDelay: 1_200,