redis / redis/node-redis

New SocketClosedUnexpectedlyError Error When Upgrading from 3 to 4 via Legacy Mode

Open
#2,273 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug stale
Dominant language
TypeScript
Stars
17.6k
Forks
2k
Avg merge
2d 3h
Merged PRs (30d)
40

Description

Hey all -- I'm not sure if this is a bug or just some "how do I redis" questions -- if there's a better place for this please let me know.

We have some old redis code that uses the callback APIs that we want to keep running by using legacy mode. However, when we run our code (that's shaped a bit like this simplified example)

var redis = require('redis')
var client = redis.createClient({
    port: '6379',
    host: process.env.REDIS_HOST,
    legacyMode: true
})

client.on('error', err => console.log('client error', err));
client.on('connect', () => console.log('client is connect'));
client.on('reconnecting', () => console.log('client is reconnecting'));
client.on('ready', () => console.log('client is ready'));

client.connect()
client.flushall(function (err, reply) {
    client.set('key', 'value', function (err, replies) {
      console.log("key set done")
      client.quit()
    })
})
console.log("main done")

we end up with a new SocketClosedUnexpectedlyError error, and then the program hangs without exiting

% node working.js
main done
client is connect
client is ready
key set done
client error SocketClosedUnexpectedlyError: Socket closed unexpectedly
    at Socket.<anonymous> (/Users/astorm/Documents/redis4/node_modules/@redis/client/dist/lib/client/socket.js:182:118)
    at Object.onceWrapper (events.js:422:26)
    at Socket.emit (events.js:315:20)
    at TCP.<anonymous> (net.js:673:12)
client is reconnecting
client is connect
client is ready
// program hangs

With redis@3.1.2 this program runs (minus the client.connect()) without issue and exits with a status code of zero (the real program we have is more complicated, this is the simplified example of the behavior we're seeing)

  1. Is there any known issue what would lead to this sort of calling pattern producing a SocketClosedUnexpectedlyError error?

  2. Do you have any theories on why the program just hangs at the end? (I'd presume a client that's waiting to disconnect)

  3. Is there a way to tell the client is should not automatically reconnect when this sort of error happens?

Environment:

  • Node.js Version: v14.16.1 and v18.4.0
  • Redis Server Version: 7.0.5 (docker redis:latest)
  • Node Redis Version: 4.3.1
  • Platform: Docker Desktop on MacOS 10.15.7

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the legacyMode callback example with Node.js 14 or 18, Redis 7.0.5, and node-redis 4.3.1. Start at @redis/client/dist/lib/client/socket.js around the reported error and trace client.connect(), quit(), and reconnecting behavior; done means explaining or correcting the unexpected close, automatic reconnect, and hanging process.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, redis
Domain
backend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.