Skip to content

Commit ba0a983

Browse files
fix(pubsub): surface TLS config errors instead of silently degrading
resolveRedisTlsOptions (via getRedisConnectionDefaults) throws if REDIS_TLS_SERVERNAME is missing for an IP-based rediss:// URL. Calling it inside the constructor let createPubSubChannel's try/catch swallow the error and fall back to in-process EventEmitter — silent cross-replica pub/sub breakage in prod. Resolve defaults before the try so config errors propagate; only catch genuine runtime construction failures.
1 parent e2d7e36 commit ba0a983

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

apps/sim/lib/events/pubsub.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ class RedisPubSubChannel<T> implements PubSubChannel<T> {
3232

3333
constructor(
3434
redisUrl: string,
35+
connectionDefaults: ReturnType<typeof getRedisConnectionDefaults>,
3536
private config: PubSubChannelConfig
3637
) {
3738
const commonOpts = {
38-
...getRedisConnectionDefaults(redisUrl),
39+
...connectionDefaults,
3940
maxRetriesPerRequest: null,
4041
retryStrategy: (times: number) => {
4142
if (times > 10) return 30000
@@ -138,16 +139,18 @@ class LocalPubSubChannel<T> implements PubSubChannel<T> {
138139

139140
export function createPubSubChannel<T>(config: PubSubChannelConfig): PubSubChannel<T> {
140141
const redisUrl = env.REDIS_URL
141-
142-
if (redisUrl) {
143-
try {
144-
logger.info(`${config.label}: Using Redis`)
145-
return new RedisPubSubChannel<T>(redisUrl, config)
146-
} catch (err) {
147-
logger.error(`Failed to create Redis ${config.label}, falling back to local:`, err)
148-
return new LocalPubSubChannel<T>(config)
149-
}
142+
if (!redisUrl) return new LocalPubSubChannel<T>(config)
143+
144+
// Resolve config-derived defaults outside the try so a missing
145+
// REDIS_TLS_SERVERNAME (config error) surfaces instead of silently degrading
146+
// to the in-process EventEmitter — that would break cross-replica pub/sub.
147+
const connectionDefaults = getRedisConnectionDefaults(redisUrl)
148+
149+
try {
150+
logger.info(`${config.label}: Using Redis`)
151+
return new RedisPubSubChannel<T>(redisUrl, connectionDefaults, config)
152+
} catch (err) {
153+
logger.error(`Failed to create Redis ${config.label}, falling back to local:`, err)
154+
return new LocalPubSubChannel<T>(config)
150155
}
151-
152-
return new LocalPubSubChannel<T>(config)
153156
}

0 commit comments

Comments
 (0)