You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
New SocketClosedUnexpectedlyError Error When Upgrading from 3 to 4 via Legacy Mode #2273
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)
Is there any known issue what would lead to this sort of calling pattern producing a SocketClosedUnexpectedlyError error?
Do you have any theories on why the program just hangs at the end? (I'd presume a client that's waiting to disconnect)
Is there a way to tell the client is should not automatically reconnect when this sort of error happens?
This issue has been automatically marked as stale due to inactivity.
It will be closed in 30 days if no further activity occurs.
If you believe this issue is still relevant, please add a comment to keep it open.
Activity
dextertanyj commentedon Sep 24, 2022
I ran into a similar issue and resolved it by using
client.v4.quit()instead.github-actions commentedon Aug 30, 2026
This issue has been automatically marked as stale due to inactivity.
It will be closed in 30 days if no further activity occurs.
If you believe this issue is still relevant, please add a comment to keep it open.