Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
6 changes: 6 additions & 0 deletions 6 .server-changes/harden-realtime-change-publishing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
area: webapp
type: improvement
---

Harden the native realtime backend's run-change publishing so a publish can never throw into a run lifecycle operation and never buffers commands in memory during a pub/sub Redis outage.
8 changes: 8 additions & 0 deletions 8 apps/webapp/app/redis.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export type RedisWithClusterOptions = {
clusterMode?: boolean;
clusterOptions?: Omit<ClusterOptions, "redisOptions">;
keyPrefix?: string;
/** Cap retries for a command before it rejects; `null` means unlimited (default: ioredis's default of 20). */
maxRetriesPerRequest?: number | null;
};

export type RedisClient = Redis | Cluster;
Expand Down Expand Up @@ -44,6 +46,9 @@ export function createRedisClient(
password: options.password,
enableAutoPipelining: true,
reconnectOnError: defaultReconnectOnError,
...(options.maxRetriesPerRequest !== undefined
? { maxRetriesPerRequest: options.maxRetriesPerRequest }
: {}),
...(options.tlsDisabled
? {
checkServerIdentity: () => {
Expand Down Expand Up @@ -72,6 +77,9 @@ export function createRedisClient(
enableAutoPipelining: true,
keyPrefix: options.keyPrefix,
reconnectOnError: defaultReconnectOnError,
...(options.maxRetriesPerRequest !== undefined
? { maxRetriesPerRequest: options.maxRetriesPerRequest }
: {}),
...(options.tlsDisabled ? {} : { tls: {} }),
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,13 @@ export class RunChangeNotifier {

#ensurePublisher(): RedisClient {
if (!this.#publisher) {
this.#publisher = createRedisClient(`${this.#connectionName}:pub`, this.options.redis);
// Publishes are fire-and-forget with a consumer-side backstop, so a dropped publish is
// latency-only. Cap retries (vs ioredis's default 20) so a pub/sub outage rejects publishes
// after ~1 reconnect cycle instead of buffering them in memory across the fleet.
this.#publisher = createRedisClient(`${this.#connectionName}:pub`, {
...this.options.redis,
maxRetriesPerRequest: 1,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
});
}
return this.#publisher;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getMeter } from "@internal/tracing";
import { env } from "~/env.server";
import { singleton } from "~/utils/singleton";
import { logger } from "../logger.server";
import { RunChangeNotifier, type ChangeRecordInput } from "./runChangeNotifier.server";

/**
Expand Down Expand Up @@ -74,12 +75,24 @@ export function publishChangeRecord(input: ChangeRecordInput): void {
if (!nativeBackendEnabled) {
return;
}
getRunChangeNotifier().publish(input);
// Publish runs on the run-engine event bus / metadata flush loop; lazy init + encoding happen
// before the notifier's own try/catch, so guard the whole call — it must never throw at its caller.
try {
getRunChangeNotifier().publish(input);
} catch (error) {
logger.error("[runChangeNotifier] publishChangeRecord threw; dropping notification", { error });
}
}

export function publishManyChangeRecords(inputs: ChangeRecordInput[]): void {
if (!nativeBackendEnabled) {
return;
}
getRunChangeNotifier().publishMany(inputs);
try {
getRunChangeNotifier().publishMany(inputs);
} catch (error) {
logger.error("[runChangeNotifier] publishManyChangeRecords threw; dropping notifications", {
error,
});
}
}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.