Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
astorm opened this issue Sep 22, 2022 · 1 comment
Labels

Comments

@astorm
Copy link

astorm commented Sep 22, 2022

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 [email protected] 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
@astorm astorm added the Bug label Sep 22, 2022
@dextertanyj
Copy link

dextertanyj commented Sep 24, 2022

I ran into a similar issue and resolved it by using client.v4.quit() instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants