From d308bfa3992968f087c55c6a906b537feaa76e6d Mon Sep 17 00:00:00 2001
From: Yashu Mittal <mittalyashu77@gmail.com>
Date: Wed, 14 Aug 2024 12:08:37 +0000
Subject: [PATCH] fix: support for IPv6 redis connections

---
 apps/webapp/app/services/autoIncrementCounter.server.ts       | 4 ++++
 apps/webapp/app/services/rateLimiter.server.ts                | 4 ++++
 apps/webapp/app/services/runExecutionRateLimiter.server.ts    | 4 ++++
 apps/webapp/app/v3/eventRepository.server.ts                  | 4 ++++
 apps/webapp/app/v3/handleSocketIo.server.ts                   | 4 ++++
 apps/webapp/app/v3/marqs/devPubSub.server.ts                  | 4 ++++
 apps/webapp/app/v3/marqs/index.server.ts                      | 4 ++++
 apps/webapp/app/v3/marqs/v2.server.ts                         | 4 ++++
 apps/webapp/app/v3/services/projectPubSub.server.ts           | 4 ++++
 .../app/v3/services/taskRunConcurrencyTracker.server.ts       | 4 ++++
 10 files changed, 40 insertions(+)

diff --git a/apps/webapp/app/services/autoIncrementCounter.server.ts b/apps/webapp/app/services/autoIncrementCounter.server.ts
index b5484af4e3..234e7ee15c 100644
--- a/apps/webapp/app/services/autoIncrementCounter.server.ts
+++ b/apps/webapp/app/services/autoIncrementCounter.server.ts
@@ -89,6 +89,10 @@ function getAutoIncrementCounter() {
       username: env.REDIS_USERNAME,
       password: env.REDIS_PASSWORD,
       enableAutoPipelining: true,
+      // Force support for both IPv6 and IPv4, by default ioredis sets this to 4,
+      // only allowing IPv4 connections:
+      // https://github.com/redis/ioredis/issues/1576
+      family: 0,
       ...(env.REDIS_TLS_DISABLED === "true" ? {} : { tls: {} }),
     },
   });
diff --git a/apps/webapp/app/services/rateLimiter.server.ts b/apps/webapp/app/services/rateLimiter.server.ts
index 8d6c03a1a6..529dde35e7 100644
--- a/apps/webapp/app/services/rateLimiter.server.ts
+++ b/apps/webapp/app/services/rateLimiter.server.ts
@@ -29,6 +29,10 @@ export class RateLimiter {
           username: env.REDIS_USERNAME,
           password: env.REDIS_PASSWORD,
           enableAutoPipelining: true,
+          // Force support for both IPv6 and IPv4, by default ioredis sets this to 4,
+          // only allowing IPv4 connections:
+          // https://github.com/redis/ioredis/issues/1576
+          family: 0,
           ...(env.REDIS_TLS_DISABLED === "true" ? {} : { tls: {} }),
         }
       ),
diff --git a/apps/webapp/app/services/runExecutionRateLimiter.server.ts b/apps/webapp/app/services/runExecutionRateLimiter.server.ts
index df82574dcb..17d809dcb4 100644
--- a/apps/webapp/app/services/runExecutionRateLimiter.server.ts
+++ b/apps/webapp/app/services/runExecutionRateLimiter.server.ts
@@ -402,6 +402,10 @@ function getRateLimiter() {
           username: env.REDIS_USERNAME,
           password: env.REDIS_PASSWORD,
           enableAutoPipelining: true,
+          // Force support for both IPv6 and IPv4, by default ioredis sets this to 4,
+          // only allowing IPv4 connections:
+          // https://github.com/redis/ioredis/issues/1576
+          family: 0,
           ...(env.REDIS_TLS_DISABLED === "true" ? {} : { tls: {} }),
         },
         defaultConcurrency: env.DEFAULT_ORG_EXECUTION_CONCURRENCY_LIMIT,
diff --git a/apps/webapp/app/v3/eventRepository.server.ts b/apps/webapp/app/v3/eventRepository.server.ts
index 989ba2b27c..160b82dc27 100644
--- a/apps/webapp/app/v3/eventRepository.server.ts
+++ b/apps/webapp/app/v3/eventRepository.server.ts
@@ -1134,6 +1134,10 @@ function initializeEventRepo() {
       username: env.REDIS_USERNAME,
       password: env.REDIS_PASSWORD,
       enableAutoPipelining: true,
+      // Force support for both IPv6 and IPv4, by default ioredis sets this to 4,
+      // only allowing IPv4 connections:
+      // https://github.com/redis/ioredis/issues/1576
+      family: 0,
       ...(env.REDIS_TLS_DISABLED === "true" ? {} : { tls: {} }),
     },
   });
diff --git a/apps/webapp/app/v3/handleSocketIo.server.ts b/apps/webapp/app/v3/handleSocketIo.server.ts
index 5b2c600166..20d74fa8a8 100644
--- a/apps/webapp/app/v3/handleSocketIo.server.ts
+++ b/apps/webapp/app/v3/handleSocketIo.server.ts
@@ -54,6 +54,10 @@ function initializeSocketIOServerInstance() {
       username: env.REDIS_USERNAME,
       password: env.REDIS_PASSWORD,
       enableAutoPipelining: true,
+      // Force support for both IPv6 and IPv4, by default ioredis sets this to 4,
+      // only allowing IPv4 connections:
+      // https://github.com/redis/ioredis/issues/1576
+      family: 0,
       ...(env.REDIS_TLS_DISABLED === "true" ? {} : { tls: {} }),
     });
     const subClient = pubClient.duplicate();
diff --git a/apps/webapp/app/v3/marqs/devPubSub.server.ts b/apps/webapp/app/v3/marqs/devPubSub.server.ts
index 974500b1a7..8f876042f3 100644
--- a/apps/webapp/app/v3/marqs/devPubSub.server.ts
+++ b/apps/webapp/app/v3/marqs/devPubSub.server.ts
@@ -26,6 +26,10 @@ function initializeDevPubSub() {
       username: env.REDIS_USERNAME,
       password: env.REDIS_PASSWORD,
       enableAutoPipelining: true,
+      // Force support for both IPv6 and IPv4, by default ioredis sets this to 4,
+      // only allowing IPv4 connections:
+      // https://github.com/redis/ioredis/issues/1576
+      family: 0,
       ...(env.REDIS_TLS_DISABLED === "true" ? {} : { tls: {} }),
     },
     schema: messageCatalog,
diff --git a/apps/webapp/app/v3/marqs/index.server.ts b/apps/webapp/app/v3/marqs/index.server.ts
index 373908af14..3b4ccaf22d 100644
--- a/apps/webapp/app/v3/marqs/index.server.ts
+++ b/apps/webapp/app/v3/marqs/index.server.ts
@@ -1720,6 +1720,10 @@ function getMarQSClient() {
         username: env.REDIS_USERNAME,
         password: env.REDIS_PASSWORD,
         enableAutoPipelining: true,
+        // Force support for both IPv6 and IPv4, by default ioredis sets this to 4,
+        // only allowing IPv4 connections:
+        // https://github.com/redis/ioredis/issues/1576
+        family: 0,
         ...(env.REDIS_TLS_DISABLED === "true" ? {} : { tls: {} }),
       };
 
diff --git a/apps/webapp/app/v3/marqs/v2.server.ts b/apps/webapp/app/v3/marqs/v2.server.ts
index c25e916d17..163b732719 100644
--- a/apps/webapp/app/v3/marqs/v2.server.ts
+++ b/apps/webapp/app/v3/marqs/v2.server.ts
@@ -64,6 +64,10 @@ function getMarQSClient() {
     username: env.REDIS_USERNAME,
     password: env.REDIS_PASSWORD,
     enableAutoPipelining: true,
+    // Force support for both IPv6 and IPv4, by default ioredis sets this to 4,
+    // only allowing IPv4 connections:
+    // https://github.com/redis/ioredis/issues/1576
+    family: 0,
     ...(env.REDIS_TLS_DISABLED === "true" ? {} : { tls: {} }),
   };
 
diff --git a/apps/webapp/app/v3/services/projectPubSub.server.ts b/apps/webapp/app/v3/services/projectPubSub.server.ts
index 7c2f7c6c05..89cf84a27d 100644
--- a/apps/webapp/app/v3/services/projectPubSub.server.ts
+++ b/apps/webapp/app/v3/services/projectPubSub.server.ts
@@ -27,6 +27,10 @@ function initializeProjectPubSub() {
       username: env.REDIS_USERNAME,
       password: env.REDIS_PASSWORD,
       enableAutoPipelining: true,
+      // Force support for both IPv6 and IPv4, by default ioredis sets this to 4,
+      // only allowing IPv4 connections:
+      // https://github.com/redis/ioredis/issues/1576
+      family: 0,
       ...(env.REDIS_TLS_DISABLED === "true" ? {} : { tls: {} }),
     },
     schema: messageCatalog,
diff --git a/apps/webapp/app/v3/services/taskRunConcurrencyTracker.server.ts b/apps/webapp/app/v3/services/taskRunConcurrencyTracker.server.ts
index 451a5e20ba..f8f426d11e 100644
--- a/apps/webapp/app/v3/services/taskRunConcurrencyTracker.server.ts
+++ b/apps/webapp/app/v3/services/taskRunConcurrencyTracker.server.ts
@@ -301,6 +301,10 @@ function getTracker() {
       username: env.REDIS_USERNAME,
       password: env.REDIS_PASSWORD,
       enableAutoPipelining: true,
+      // Force support for both IPv6 and IPv4, by default ioredis sets this to 4,
+      // only allowing IPv4 connections:
+      // https://github.com/redis/ioredis/issues/1576
+      family: 0,
       ...(env.REDIS_TLS_DISABLED === "true" ? {} : { tls: {} }),
     },
   });