Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

319
Views
@socket.io/redis-adapter and redis; sub client doesn't reconnect after error

Given that I'm importing these packages:

import {Socket, Server} from 'socket.io'; // @4.4.1
import {createClient} from 'redis'; // @4.0.4
import {createAdapter} from '@socket.io/redis-adapter'; // @7.1.0
import {Server as HttpServer} from 'http'; // npm@8.5.5, node@v17.7.0

I have a Server that I've created with:

  const http = HttpServer // from 'http', creation not in this code
  const io = new Server(http, {
    path: '/socket/v1/tunnel',
    serveClient: false,
    cookie: false,
    pingTimeout: 295000,
    pingInterval: 300000,
  });

and Redis pub/sub clients that I've created with:

  const pubClient = createClient({
    url: redisAddress,
  });
  const subClient = pubClient.duplicate();

After I have these I connect the Redis clients and add them to an adapter (in io) with the following:

  Promise.all([pubClient.connect(), subClient.connect()]).then(() => {
    io.adapter(createAdapter(pubClient, subClient));
...
  }

With the above I have a working socket server. My problem is that every ~1 hour my connection to the Redis clients errors out. The pubClient reconnects immediately (as I expect it to do as per documentation), but the subClient errors and doesn't reconnect.

I can emit to rooms in Redis from other systems, and while this subClient is connected messages get passed along to the appropriate devices. After the subClient errors the first time (which it does fairly predictably on an interval of about 1 hour) it doesn't reconnect which means that emits to Redis rooms no longer get routed to their destinations.

I have a few questions:

  1. Why doesn't the Redis Client reconnect? The pubClient reconnects after errors consistently, but the subClient does not. According to Redis documentation it should reconnect automatically, why doesn't it?
  2. How can I configure the subClient to reconnect after errors? should I add a subClient.connect() inside of the handler for subClient.on('error', () => {...}, or have I configured this incorrectly and should make a new distinct client with createClient({...})?
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This problem was being caused by the redis package. redis@4 does not reconnect on pub/sub channels properly (currently, v4.0.4). Downgrading redis to v3.1.2 solved the reconnect issue entirely

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!