fix(redis): apply TLS SNI override to pub/sub clients#4638
Conversation
Pub/sub clients in lib/events/pubsub.ts build their own ioredis instances directly via new Redis(redisUrl, ...) because pub/sub needs dedicated connections (can't multiplex on the shared client from getRedisClient). That path skipped the resolveTlsOptions helper added for trigger.dev's PrivateLink VPCE IP, so every pub/sub channel hit 'Hostname/IP does not match certificate's altnames' on connect. Export the helper as resolveRedisTlsOptions and use it from pubsub.ts.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Updates Reviewed by Cursor Bugbot for commit ba0a983. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b58fa66. Configure here.
Greptile SummaryThis PR fixes a TLS SNI mismatch on trigger.dev tasks by applying the
Confidence Score: 4/5Safe to merge for the targeted PrivateLink/SNI fix; the only concern is a pre-existing fallback that would swallow a misconfiguration error rather than surfacing it. The fix is correct and minimal: TLS options are now consistently applied to all three Redis connections (main, pub, sub). The one edge case is that if apps/sim/lib/events/pubsub.ts — the existing error-swallowing fallback in Important Files Changed
Sequence DiagramsequenceDiagram
participant pubsub as pubsub.ts
participant helper as resolveRedisTlsOptions
participant env as REDIS_TLS_SERVERNAME
participant redis as ioredis (pub/sub)
pubsub->>helper: resolveRedisTlsOptions(redisUrl)
helper->>helper: parse URL, check rediss:// + IP host
helper->>env: read REDIS_TLS_SERVERNAME
alt REDIS_TLS_SERVERNAME set
helper-->>pubsub: "{ servername: "elasticache-dns" }"
pubsub->>redis: "new Redis(redisUrl, { tls: { servername } })"
redis-->>pubsub: connected (SNI override applied)
else REDIS_TLS_SERVERNAME missing
helper-->>pubsub: throws Error
Note over pubsub: caught by createPubSubChannel try-catch
pubsub->>pubsub: fallback to LocalPubSubChannel
end
|
Extract keepAlive/connectTimeout/enableOfflineQueue + TLS SNI into a single getRedisConnectionDefaults helper. Main client and pub/sub clients both spread it; caller-specific retry/timeout policy stays per-caller (pub/sub still needs maxRetriesPerRequest: null and a different retry strategy for SUBSCRIBE).
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.

lib/events/pubsub.tswere building their own ioredis instances directly (pub/sub needs dedicated connections), bypassing the SNI override added in feat(redis): TLS SNI override for IP-based REDIS_URL + zod schema fixes #4635. trigger.dev tasks hit 'Hostname/IP does not match certificate's altnames' on every pub/sub connect against the PrivateLink VPCE IP. Export the helper asresolveRedisTlsOptionsand apply it to the pub/sub clients too.