Open History to see the last commit
1import type { RelayManagedEndpointRuntimeConfig } from "@t3tools/contracts/relay";
2import * as RelayClient from "@t3tools/shared/relayClient";
3import * as Clock from "effect/Clock";
4import * as Context from "effect/Context";
5import * as Duration from "effect/Duration";
6import * as Effect from "effect/Effect";
7import * as Exit from "effect/Exit";
8import * as Layer from "effect/Layer";
9import * as Queue from "effect/Queue";
10import * as Ref from "effect/Ref";
11import * as Result from "effect/Result";
12import * as Semaphore from "effect/Semaphore";
13import * as Scope from "effect/Scope";
14import * as Stream from "effect/Stream";
15import * as ChildProcess from "effect/process/ChildProcess";
16import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
17
18export type CloudManagedEndpointRuntimeStatus =
19 | {
20 readonly status: "disabled";
21 }
22 | {
23 readonly status: "failed";
24 readonly providerKind: RelayManagedEndpointRuntimeConfig["providerKind"];
25 readonly failure: "unsupported-platform" | "not-installed" | "spawn-failed";
26 readonly reason: string;
27 readonly tunnelId?: string;
28 readonly tunnelName?: string;
29 }
30 | {
31 readonly status: "running";
32 readonly providerKind: "cloudflare_tunnel";
33 readonly pid: number;
34 readonly tunnelId?: string;
35 readonly tunnelName?: string;
36 }
37 | {
38 readonly status: "unsupported";
39 readonly providerKind: RelayManagedEndpointRuntimeConfig["providerKind"];
40 };
41
42export class CloudManagedEndpointRuntime extends Context.Service<
43 CloudManagedEndpointRuntime,
44 {
45 readonly applyConfig: (
46 config: RelayManagedEndpointRuntimeConfig | null,
47 ) => Effect.Effect<CloudManagedEndpointRuntimeStatus>;
48 readonly recoveryRequests: Stream.Stream<RelayManagedEndpointRuntimeConfig>;
49 readonly requestRecovery: (config: RelayManagedEndpointRuntimeConfig) => Effect.Effect<void>;
50 /** Emits when the connector registers a tunnel connection, i.e. the relay can reach us again. */
51 readonly tunnelConnected: Stream.Stream<void>;
52 readonly withLinkStateLock: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
53 }
54>()("t3/cloud/ManagedEndpointRuntime/CloudManagedEndpointRuntime") {}
55
56interface ActiveConnector {
57 readonly child: ChildProcessSpawner.ChildProcessHandle;
58 readonly executable: RelayClient.AvailableRelayClient;
59 readonly scope: Scope.Closeable;
60 readonly configKey: string;
61 readonly config: RelayManagedEndpointRuntimeConfig;
62 readonly startedAtMillis: number;
63 readonly connected: Ref.Ref<boolean>;
64}
65
66// A connector that exits before running this long is treated as part of a
67// crash loop; one that stays up at least this long earns an immediate restart
68// again. Without the backoff below, a relay client that fails instantly (a
69// stale version-manager shim, a bad binary) respawns ~100 times per second
70// until the accumulated tracing exhausts the V8 heap.
71const RELAY_RESTART_STABLE_UPTIME_MS = 30_000;
72const RELAY_RESTART_BACKOFF_BASE_MS = 1_000;
73const RELAY_RESTART_BACKOFF_MAX_MS = 60_000;
74// Newly created tunnels can fail authorization briefly while Cloudflare propagates their token.
75const TUNNEL_AUTHORIZATION_FAILURES_BEFORE_RECOVERY = 4;
76// A connector that never registers a connection may hold a token for a tunnel
77// that no longer exists, rejected in wording the output check does not know.
78// Ask for recovery after this long, and again at this interval while it stays
79// unconnected; the relay hands back the same tunnel when it is still live.
80const CONNECTOR_REGISTRATION_TIMEOUT = Duration.minutes(3);
81// A failed background install of the pinned relay client is retried no sooner
82// than this, so a crash-looping connector or an offline host does not redownload
83// on every reconcile.
84const RELAY_CLIENT_INSTALL_RETRY_INTERVAL_MS = 10 * 60_000;
85
86/**
87 * A linked host converges on the pinned managed release when it has no relay
88 * client or runs another managed release. A PATH binary or an explicit override
89 * is the user's choice, and the CLI asks before downloading, so both stay put.
90 */
91function needsPinnedRelayClient(executable: RelayClient.RelayClientStatus): boolean {
92 return (
93 executable.status === "missing" ||
94 (executable.status === "available" &&
95 executable.source === "managed" &&
96 !RelayClient.isPinnedManagedRelayClient(executable))
97 );
98}
99
100export function classifyRelayClientOutput(line: string): "connected" | "warning" | "debug" {
101 if (/\bRegistered tunnel connection\b/iu.test(line)) {
102 return "connected";
103 }
104 // cloudflared uses zerolog level tokens. FTL (fatal) and PNC (panic) are more
105 // severe than ERR, so they must surface at least as loudly — without them a
106 // fatal connector failure would be logged at debug and hidden.
107 return /\b(?:ERR|WRN|FTL|PNC)\b/u.test(line) ? "warning" : "debug";
108}
109
110/**
111 * Cloudflare's edge rejects a connector whose tunnel was deleted or whose
112 * token no longer matches. The edge words this differently over time
113 * (`Failed to get tunnel`, `Tunnel not found`, ...), sometimes prefixed with
114 * `Unauthorized:`. Treat any `Unauthorized:` registration error as a rejection,
115 * plus the unprefixed messages seen so far. Transient rejections while a new
116 * tunnel's token propagates are absorbed by requiring several in a row.
117 */
118export function isRejectedRelayClientTunnelOutput(line: string): boolean {
119 return (
120 /\bRegister tunnel error from server side\b/iu.test(line) &&
121 /error="(?:Unauthorized:[^"]*|Failed to get tunnel|Tunnel not found|Record for tunnel not found|Invalid tunnel secret)"/iu.test(
122 line,
123 )
124 );
125}
126
127/** Connector startup failures can clear after installation or a later spawn attempt. */
128export function isRetryableManagedEndpointRuntimeStatus(status: unknown): boolean {
129 if (typeof status !== "object" || status === null || !("status" in status)) {
130 return false;
131 }
132 if (status.status !== "failed" || !("failure" in status)) {
133 return false;
134 }
135 return status.failure === "not-installed" || status.failure === "spawn-failed";
136}
137
138function runtimeConfigKey(config: RelayManagedEndpointRuntimeConfig): string {
139 return JSON.stringify({
140 providerKind: config.providerKind,
141 connectorToken: config.connectorToken,
142 tunnelId: config.tunnelId ?? null,
143 tunnelName: config.tunnelName ?? null,
144 });
145}
146
147const stopConnector = (connector: ActiveConnector | null) =>
148 connector
149 ? Scope.close(connector.scope, Exit.void).pipe(
150 Effect.tap(() =>
151 Effect.logInfo("Relay client stopped", {
152 pid: Number(connector.child.pid),
153 }),
154 ),
155 Effect.ignore,
156 )
157 : Effect.void;
158
159/** @public Service construction is part of the canonical Effect module API. */
160export const make = Effect.gen(function* () {
161 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
162 const relayClient = yield* RelayClient.RelayClient;
163 const activeRef = yield* Ref.make<ActiveConnector | null>(null);
164 const desiredConfigRef = yield* Ref.make<RelayManagedEndpointRuntimeConfig | null>(null);
165 const recoveryRequests = yield* Queue.sliding<RelayManagedEndpointRuntimeConfig>(1);
166 const tunnelConnections = yield* Queue.sliding<void>(1);
167 const reconcileSemaphore = yield* Semaphore.make(1);
168 const restartDelayRef = yield* Ref.make(0);
169 const linkStateSemaphore = yield* Semaphore.make(1);
170 const runtimeScope = yield* Effect.scope;
171 const installInFlightRef = yield* Ref.make(false);
172 const lastInstallFailureAtRef = yield* Ref.make<number | null>(null);
173 const prunedRef = yield* Ref.make(false);
174 const retryLoopRunningRef = yield* Ref.make(false);
175 let reconcileConfig: CloudManagedEndpointRuntime["Service"]["applyConfig"];
176
177 const stopActive = Effect.gen(function* () {
178 const active = yield* Ref.getAndSet(activeRef, null);
179 yield* stopConnector(active);
180 });
181
182 const superviseConnector = (connector: ActiveConnector) =>
183 Effect.gen(function* () {
184 const result = yield* Effect.result(connector.child.exitCode);
185 const activeAtExit = yield* Ref.get(activeRef);
186 if (
187 activeAtExit?.child.pid !== connector.child.pid ||
188 activeAtExit.configKey !== connector.configKey
189 ) {
190 return;
191 }
192 const uptimeMillis = (yield* Clock.currentTimeMillis) - connector.startedAtMillis;
193 // The first crash restarts immediately; every further crash inside the
194 // stable-uptime window doubles the wait, up to the cap. The delay runs
195 // before the semaphore so a user config change is never blocked behind
196 // it, and reconcileConfig re-checks the desired config afterwards.
197 const restartDelayMillis = yield* Ref.modify(restartDelayRef, (current) => {
198 if (uptimeMillis >= RELAY_RESTART_STABLE_UPTIME_MS) {
199 return [0, 0];
200 }
201 return [
202 current,
203 current === 0
204 ? RELAY_RESTART_BACKOFF_BASE_MS
205 : Math.min(current * 2, RELAY_RESTART_BACKOFF_MAX_MS),
206 ];
207 });
208 if (restartDelayMillis > 0) {
209 yield* Effect.logWarning("Relay client is crash-looping; delaying restart", {
210 pid: Number(connector.child.pid),
211 uptimeMillis,
212 restartDelayMillis,
213 tunnelId: connector.config.tunnelId,
214 tunnelName: connector.config.tunnelName,
215 });
216 yield* Effect.sleep(Duration.millis(restartDelayMillis));
217 }
218 yield* reconcileSemaphore.withPermits(1)(
219 Effect.gen(function* () {
220 const active = yield* Ref.get(activeRef);
221 if (
222 active?.child.pid !== connector.child.pid ||
223 active.configKey !== connector.configKey
224 ) {
225 return;
226 }
227 yield* Ref.set(activeRef, null);
228 yield* stopConnector(connector);
229
230 const desiredConfig = yield* Ref.get(desiredConfigRef);
231 if (
232 !desiredConfig ||
233 desiredConfig.providerKind !== "cloudflare_tunnel" ||
234 runtimeConfigKey(desiredConfig) !== connector.configKey
235 ) {
236 return;
237 }
238
239 yield* Effect.logWarning("Relay client exited; restarting", {
240 pid: Number(connector.child.pid),
241 ...(Result.isSuccess(result)
242 ? { exitCode: Number(result.success) }
243 : { cause: result.failure }),
244 tunnelId: connector.config.tunnelId,
245 tunnelName: connector.config.tunnelName,
246 });
247 yield* Queue.offer(recoveryRequests, connector.config);
248 yield* reconcileConfig(desiredConfig);
249 }),
250 );
251 }).pipe(
252 Effect.catchCause((cause) => Effect.logWarning("Relay client supervisor failed", { cause })),
253 );
254
255 // Installs the pinned relay client in the background, then restarts the
256 // connector on it. The running connector, if any, keeps serving until the new
257 // binary is installed and validated, so an update costs one brief reconnect.
258 const installPinnedRelayClient = Effect.gen(function* () {
259 if (yield* Ref.getAndSet(installInFlightRef, true)) return;
260 yield* Effect.logInfo("Installing the pinned relay client", {
261 version: RelayClient.CLOUDFLARED_VERSION,
262 });
263 yield* relayClient.install.pipe(
264 Effect.tap(() => Ref.set(lastInstallFailureAtRef, null)),
265 Effect.flatMap((installed) =>
266 reconcileSemaphore.withPermits(1)(
267 Effect.gen(function* () {
268 const desiredConfig = yield* Ref.get(desiredConfigRef);
269 if (!desiredConfig || desiredConfig.providerKind !== "cloudflare_tunnel") return;
270 const active = yield* Ref.get(activeRef);
271 // A self-updated binary in the pinned folder shares the installed path,
272 // so the version decides whether the running connector is current.
273 if (
274 active?.executable.executablePath === installed.executablePath &&
275 active.executable.version === installed.version
276 ) {
277 return;
278 }
279 // A fresh binary can fail its probe while a scanner holds it; restarting
280 // then would land on the same older binary, so leave it to the retry.
281 const resolved = yield* relayClient.resolve;
282 if (
283 resolved.status !== "available" ||
284 resolved.executablePath !== installed.executablePath ||
285 resolved.version !== installed.version
286 ) {
287 return;
288 }
289 yield* Effect.logInfo("Relay client installed; restarting the connector on it", {
290 version: installed.version,
291 previousVersion: active?.executable.version,
292 });
293 yield* stopActive;
294 const status = yield* reconcileConfig(desiredConfig);
295 // The old connector is gone and no supervisor watches a failed spawn,
296 // so ask for recovery like an exited connector would.
297 if (status.status === "failed") {
298 yield* Effect.logWarning("Relay client did not start after the update", status);
299 yield* Queue.offer(recoveryRequests, desiredConfig);
300 }
301 }),
302 ),
303 ),
304 Effect.catchTags({
305 RelayClientInstallError: (error) =>
306 Clock.currentTimeMillis.pipe(
307 Effect.flatMap((failedAt) => Ref.set(lastInstallFailureAtRef, failedAt)),
308 Effect.andThen(
309 Effect.logWarning("Could not install the pinned relay client", {
310 reason: error.reason,
311 message: error.message,
312 cause: error.cause,
313 }),
314 ),
315 ),
316 }),
317 Effect.ensuring(Ref.set(installInFlightRef, false)),
318 );
319 });
320
321 // Reconciles call this; a recent failure skips the attempt so a crash-looping
322 // connector or an offline host does not redownload on every restart.
323 const ensurePinnedRelayClient = Effect.gen(function* () {
324 const now = yield* Clock.currentTimeMillis;
325 const lastFailureAt = yield* Ref.get(lastInstallFailureAtRef);
326 if (lastFailureAt !== null && now - lastFailureAt < RELAY_CLIENT_INSTALL_RETRY_INTERVAL_MS) {
327 return;
328 }
329 yield* installPinnedRelayClient;
330 }).pipe(Effect.forkIn(runtimeScope), Effect.asVoid);
331
332 // Until the host runs the pinned release, retry the install every interval.
333 // applyConfig returns early while an older connector is healthy, and some
334 // activations never retry a missing client, so one runtime loop covers both.
335 // It paces itself, so it skips the failure gate above.
336 const retryPinnedRelayClientInstall = Effect.gen(function* () {
337 while (true) {
338 yield* Effect.sleep(Duration.millis(RELAY_CLIENT_INSTALL_RETRY_INTERVAL_MS));
339 const desiredConfig = yield* Ref.get(desiredConfigRef);
340 if (!desiredConfig || desiredConfig.providerKind !== "cloudflare_tunnel") return;
341 // Stop only once a connector runs on the pin. The pin can be on disk while
342 // an older connector still runs, or while none runs because a post-install
343 // probe failed; another install call then finds it and starts the connector.
344 const active = yield* Ref.get(activeRef);
345 if (active && !needsPinnedRelayClient(active.executable)) return;
346 yield* installPinnedRelayClient;
347 }
348 }).pipe(Effect.ensuring(Ref.set(retryLoopRunningRef, false)));
349
350 const startPinnedRelayClientRetries = Effect.gen(function* () {
351 if (yield* Ref.getAndSet(retryLoopRunningRef, true)) return;
352 yield* Effect.forkIn(retryPinnedRelayClientInstall, runtimeScope);
353 });
354
355 // Requests recovery while the connector has not registered a connection,
356 // once per timeout, until it connects or is replaced.
357 const watchConnectorRegistration = (connector: ActiveConnector) =>
358 Effect.gen(function* () {
359 yield* Effect.sleep(CONNECTOR_REGISTRATION_TIMEOUT);
360 if (yield* Ref.get(connector.connected)) return true;
361 yield* Effect.logWarning(
362 "Relay client has not registered a tunnel connection; requesting recovery",
363 {
364 pid: Number(connector.child.pid),
365 tunnelId: connector.config.tunnelId,
366 tunnelName: connector.config.tunnelName,
367 },
368 );
369 yield* Queue.offer(recoveryRequests, connector.config);
370 return false;
371 }).pipe(Effect.repeat({ until: (connected) => connected }));
372
373 const observeConnectorOutput = (connector: ActiveConnector) => {
374 let rejectedRegistrations = 0;
375
376 return connector.child.all.pipe(
377 Stream.decodeText(),
378 Stream.splitLines,
379 Stream.map((line) => line.trim()),
380 Stream.filter((line) => line.length > 0),
381 Stream.runForEach((line) => {
382 const output = line.replaceAll(connector.config.connectorToken, "<redacted>");
383 const attributes = {
384 pid: Number(connector.child.pid),
385 tunnelId: connector.config.tunnelId,
386 tunnelName: connector.config.tunnelName,
387 output,
388 };
389 switch (classifyRelayClientOutput(line)) {
390 case "connected":
391 rejectedRegistrations = 0;
392 return Ref.set(connector.connected, true).pipe(
393 Effect.andThen(
394 Effect.logInfo("Relay client tunnel connection registered", attributes),
395 ),
396 Effect.andThen(Queue.offer(tunnelConnections, undefined)),
397 Effect.andThen(
398 RelayClient.isPinnedManagedRelayClient(connector.executable)
399 ? Ref.getAndSet(prunedRef, true).pipe(
400 Effect.flatMap((pruned) =>
401 pruned ? Effect.void : relayClient.pruneManagedVersions,
402 ),
403 )
404 : Effect.void,
405 ),
406 Effect.asVoid,
407 );
408 case "warning":
409 if (isRejectedRelayClientTunnelOutput(line)) {
410 rejectedRegistrations += 1;
411 if (rejectedRegistrations >= TUNNEL_AUTHORIZATION_FAILURES_BEFORE_RECOVERY) {
412 rejectedRegistrations = 0;
413 return Effect.logWarning(
414 "Relay client tunnel was rejected; requesting recovery",
415 attributes,
416 ).pipe(
417 Effect.andThen(Queue.offer(recoveryRequests, connector.config)),
418 Effect.asVoid,
419 );
420 }
421 }
422 return Effect.logWarning("Relay client reported a transport warning", attributes);
423 case "debug":
424 return Effect.logDebug("Relay client output", attributes);
425 }
426 }),
427 Effect.catchCause((cause) =>
428 Effect.logWarning("Relay client output observer failed", {
429 cause,
430 pid: Number(connector.child.pid),
431 tunnelId: connector.config.tunnelId,
432 tunnelName: connector.config.tunnelName,
433 }),
434 ),
435 );
436 };
437
438 reconcileConfig = Effect.fn("CloudManagedEndpointRuntime.reconcileConfig")(function* (config) {
439 if (!config || config.providerKind !== "cloudflare_tunnel") {
440 yield* stopActive;
441 return config
442 ? { status: "unsupported", providerKind: config.providerKind }
443 : { status: "disabled" };
444 }
445
446 const nextConfigKey = runtimeConfigKey(config);
447 const active = yield* Ref.get(activeRef);
448 if (active?.configKey === nextConfigKey) {
449 const isRunning = yield* active.child.isRunning.pipe(Effect.orElseSucceed(() => false));
450 if (isRunning) {
451 return {
452 status: "running",
453 providerKind: "cloudflare_tunnel",
454 pid: Number(active.child.pid),
455 ...(active.config.tunnelId ? { tunnelId: active.config.tunnelId } : {}),
456 ...(active.config.tunnelName ? { tunnelName: active.config.tunnelName } : {}),
457 } satisfies CloudManagedEndpointRuntimeStatus;
458 }
459 }
460
461 yield* stopActive;
462
463 const executable = yield* relayClient.resolve;
464 if (needsPinnedRelayClient(executable)) {
465 yield* ensurePinnedRelayClient;
466 yield* startPinnedRelayClientRetries;
467 }
468 if (executable.status !== "available") {
469 return {
470 status: "failed",
471 providerKind: "cloudflare_tunnel",
472 failure: executable.status === "unsupported" ? "unsupported-platform" : "not-installed",
473 reason:
474 executable.status === "unsupported"
475 ? `Relay client is unsupported on ${executable.platform}-${executable.arch}.`
476 : "The relay client is not installed.",
477 ...(config.tunnelId ? { tunnelId: config.tunnelId } : {}),
478 ...(config.tunnelName ? { tunnelName: config.tunnelName } : {}),
479 } satisfies CloudManagedEndpointRuntimeStatus;
480 }
481
482 const connectorScope = yield* Scope.make("sequential");
483 const child = yield* spawner
484 .spawn(
485 ChildProcess.make(
486 executable.executablePath,
487 ["tunnel", "--no-autoupdate", "--loglevel", "info", "--output", "default", "run"],
488 {
489 detached: false,
490 env: {
491 ...process.env,
492 TUNNEL_TOKEN: config.connectorToken,
493 },
494 shell: false,
495 stderr: "pipe",
496 stdout: "pipe",
497 },
498 ),
499 )
500 .pipe(
501 Effect.provideService(Scope.Scope, connectorScope),
502 Effect.tap((child) =>
503 Effect.logInfo("Relay client process started; waiting for tunnel connection", {
504 pid: Number(child.pid),
505 source: executable.source,
506 version: executable.version,
507 tunnelId: config.tunnelId,
508 tunnelName: config.tunnelName,
509 }),
510 ),
511 Effect.catch((cause) =>
512 Effect.logWarning("Failed to start relay client", {
513 cause,
514 tunnelId: config.tunnelId,
515 tunnelName: config.tunnelName,
516 }).pipe(
517 Effect.andThen(Scope.close(connectorScope, Exit.void).pipe(Effect.ignore)),
518 Effect.as({
519 status: "failed",
520 providerKind: "cloudflare_tunnel",
521 failure: "spawn-failed",
522 reason: String(cause),
523 ...(config.tunnelId ? { tunnelId: config.tunnelId } : {}),
524 ...(config.tunnelName ? { tunnelName: config.tunnelName } : {}),
525 } satisfies CloudManagedEndpointRuntimeStatus),
526 ),
527 ),
528 );
529
530 if ("status" in child && child.status === "failed") {
531 return child;
532 }
533
534 if (!("status" in child)) {
535 const connector = {
536 child,
537 executable,
538 scope: connectorScope,
539 configKey: nextConfigKey,
540 config,
541 startedAtMillis: yield* Clock.currentTimeMillis,
542 connected: yield* Ref.make(false),
543 } satisfies ActiveConnector;
544 yield* Ref.set(activeRef, connector);
545 yield* Effect.forkIn(observeConnectorOutput(connector), connectorScope);
546 yield* Effect.forkIn(superviseConnector(connector), connectorScope);
547 yield* Effect.forkIn(watchConnectorRegistration(connector), connectorScope);
548 return {
549 status: "running",
550 providerKind: "cloudflare_tunnel",
551 pid: Number(child.pid),
552 ...(config.tunnelId ? { tunnelId: config.tunnelId } : {}),
553 ...(config.tunnelName ? { tunnelName: config.tunnelName } : {}),
554 } satisfies CloudManagedEndpointRuntimeStatus;
555 }
556
557 return {
558 status: "failed",
559 providerKind: "cloudflare_tunnel",
560 failure: "spawn-failed",
561 reason: "Relay client did not start.",
562 ...(config.tunnelId ? { tunnelId: config.tunnelId } : {}),
563 ...(config.tunnelName ? { tunnelName: config.tunnelName } : {}),
564 } satisfies CloudManagedEndpointRuntimeStatus;
565 });
566
567 const applyConfig = Effect.fn("CloudManagedEndpointRuntime.applyConfig")(
568 (config: RelayManagedEndpointRuntimeConfig | null) =>
569 reconcileSemaphore.withPermits(1)(
570 Effect.gen(function* () {
571 // A real config change starts over with a fresh backoff. Recovery
572 // that hands back the same tunnel and token must keep the delay, or
573 // a crash-looping connector respawns on every recovery round trip.
574 const desired = yield* Ref.get(desiredConfigRef);
575 const unchanged =
576 desired !== null &&
577 config !== null &&
578 runtimeConfigKey(desired) === runtimeConfigKey(config);
579 if (!unchanged) {
580 yield* Ref.set(restartDelayRef, 0);
581 }
582 yield* Ref.set(desiredConfigRef, config);
583 return yield* reconcileConfig(config);
584 }),
585 ),
586 );
587
588 const runtime = CloudManagedEndpointRuntime.of({
589 applyConfig,
590 recoveryRequests: Stream.fromQueue(recoveryRequests),
591 requestRecovery: (config) => Queue.offer(recoveryRequests, config).pipe(Effect.asVoid),
592 tunnelConnected: Stream.fromQueue(tunnelConnections),
593 withLinkStateLock: linkStateSemaphore.withPermits(1),
594 });
595
596 yield* Effect.addFinalizer(() => runtime.applyConfig(null));
597 return runtime;
598});
599
600export const layer = Layer.effect(CloudManagedEndpointRuntime, make);