Skip to content

Commit 208a63d

Browse files
committed
fix(clients): reconnect after credentials fail during remote server updates
1 parent 30be311 commit 208a63d

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

‎packages/client-runtime/src/state/server.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,30 @@ describe("update restart reconnect nudges", () => {
124124
yield* Fiber.join(fiber);
125125
}).pipe(Effect.provide(TestClock.layer())),
126126
);
127+
128+
it.effect("retries rejected credentials only while the update restart is in progress", () =>
129+
Effect.gen(function* () {
130+
const retries = yield* Ref.make(0);
131+
132+
yield* nudgeReconnectDuringUpdateRestart({
133+
stateChanges: Stream.fromIterable([
134+
{ phase: "blocked", lastFailure: { reason: "permission" } },
135+
{
136+
phase: "blocked",
137+
lastFailure: {
138+
reason: "authentication",
139+
detail: "The environment credential is invalid.",
140+
},
141+
},
142+
{ phase: "blocked", lastFailure: { reason: "configuration" } },
143+
]),
144+
retryNow: Ref.update(retries, (count) => count + 1),
145+
interval: Duration.zero,
146+
});
147+
148+
expect(yield* Ref.get(retries)).toBe(1);
149+
}),
150+
);
127151
});
128152

129153
describe("server state projection", () => {

‎packages/client-runtime/src/state/server.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,30 @@ export function validateServerUpdateReadyEvent(
160160
* each nudge is the pacer: a connection that fails instantly re-enters backoff
161161
* immediately and would otherwise spin a tight retry loop.
162162
*
163+
* A newly restarted server can also reject the first environment credential.
164+
* Authentication blocks need the same paced retry during this known restart;
165+
* permission and configuration failures remain blocked.
166+
*
163167
* Callers fork this as a child of the update command so it is interrupted as
164168
* soon as the update settles, whether it succeeds, fails, or times out.
165169
*/
166170
export function nudgeReconnectDuringUpdateRestart(input: {
167-
readonly stateChanges: Stream.Stream<{ readonly phase: string }, unknown>;
171+
readonly stateChanges: Stream.Stream<
172+
{
173+
readonly phase: string;
174+
readonly lastFailure?: { readonly reason: string } | null;
175+
},
176+
unknown
177+
>;
168178
readonly retryNow: Effect.Effect<void>;
169179
readonly interval?: Duration.Duration;
170180
}): Effect.Effect<void> {
171181
return input.stateChanges.pipe(
172-
Stream.filter((state) => state.phase === "backoff"),
182+
Stream.filter(
183+
(state) =>
184+
state.phase === "backoff" ||
185+
(state.phase === "blocked" && state.lastFailure?.reason === "authentication"),
186+
),
173187
Stream.runForEach(() =>
174188
Effect.sleep(input.interval ?? Duration.seconds(1)).pipe(Effect.andThen(input.retryNow)),
175189
),

0 commit comments

Comments
 (0)