Skip to content
Merged
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
5 changes: 4 additions & 1 deletion apps/mobile/src/connection/background-activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
} from "./background-activity-scopes";

const REPORT_INTERVAL_MS = 25_000;
// Shorter than the interval, so a report that never settles cannot hold up the next one.
const REPORT_TIMEOUT_MS = 15_000;
const LEASE_TTL_MS = 45_000;
const BASELINE_SCOPES: ReadonlyArray<BackgroundScope> = [{ type: "provider-status" }];

Expand Down Expand Up @@ -83,7 +85,8 @@ export const layerReporter = Layer.effectDiscard(
)
// Not `ignore`: tearing down an environment mid-request interrupts its report,
// and an interrupt leaking out here would end the reporting loop for good.
.pipe(Effect.ignoreCause),
// The timeout covers a live connection that never answers, which would stall it.
.pipe(Effect.timeout(`${REPORT_TIMEOUT_MS} millis`), Effect.ignoreCause),
{ concurrency: "unbounded", discard: true },
);
}).pipe(Effect.withSpan("mobile.backgroundActivity.report"));
Expand Down
25 changes: 25 additions & 0 deletions apps/web/src/lib/backgroundActivityReporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,29 @@ describe("layer", () => {
expect(calls).toBe(2);
}).pipe(Effect.scoped),
);

it.effect("keeps reporting after a report never settles", () =>
Effect.gen(function* () {
const entries = yield* SubscriptionRef.make(
new Map([[EnvironmentId.make("environment-reporter-test"), {}]]),
);
let calls = 0;
const registry = EnvironmentRegistry.EnvironmentRegistry.of({
entries,
run: () => {
calls += 1;
return calls === 1 ? Effect.never : Effect.void;
},
} as unknown as EnvironmentRegistry.EnvironmentRegistry["Service"]);

yield* Layer.build(
layer.pipe(Layer.provide(Layer.succeed(EnvironmentRegistry.EnvironmentRegistry, registry))),
);
yield* TestClock.adjust("1 second");
expect(calls).toBe(1);

yield* TestClock.adjust("25 seconds");
expect(calls).toBe(2);
}).pipe(Effect.scoped),
);
});
5 changes: 4 additions & 1 deletion apps/web/src/lib/backgroundActivityReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { randomUUID } from "./utils";

const CLIENT_ID_STORAGE_KEY = "t3.backgroundActivity.clientId";
const REPORT_INTERVAL_MS = 25_000;
// Shorter than the interval, so a report that never settles cannot hold up the next one.
const REPORT_TIMEOUT_MS = 15_000;
const LEASE_TTL_MS = 45_000;
const RECENT_INTERACTION_WINDOW_MS = LEASE_TTL_MS;
const BASELINE_SCOPES: ReadonlyArray<BackgroundScope> = [{ type: "provider-status" }];
Expand Down Expand Up @@ -207,7 +209,8 @@ export const layer = Layer.effectDiscard(
)
// Not `ignore`: tearing down an environment mid-request interrupts its report,
// and an interrupt leaking out here would end the reporting loop for good.
.pipe(Effect.ignoreCause),
// The timeout covers a live connection that never answers, which would stall it.
.pipe(Effect.timeout(`${REPORT_TIMEOUT_MS} millis`), Effect.ignoreCause),
{ concurrency: "unbounded", discard: true },
);
}).pipe(Effect.withSpan("web.backgroundActivity.report"));
Expand Down
Loading