Closed wyvasi closed 2 years ago
changing from socket connection to url solved the issue on local machine connecting to docker container
redisClient = redis.createClient({
url: 'redis://127.0.0.1:6379'
});
not sure if related but I'm getting similar errors. All event listeners are configured. Application is a nestjs server dockerized on node:18-alpine, talking to memorystore redis in GCP (idle connections are not automatically closed).
client initially connects -> socket gets closed -> client tries reconnecting -> uncaught exception occurs for socket closing
"redis": "^4.6.7",
async connectToRedis(): Promise<void>{
try{
const pubClient = createClient({
socket: {
host: process.env.REDIS_HOST,
port: Number(process.env.REDIS_PORT)
},
});
const subClient = pubClient.duplicate();
pubClient.on('error', (error) => {
console.error('pubClient redis error:', error);
});
pubClient.on('connect', () => console.log('pubClient redis is connected'));
pubClient.on('reconnecting', () => console.log('pubClient redis is reconnecting'));
pubClient.on('ready', () => console.log('pubClient redis is ready'));
subClient.on('error', (error) => {
console.error('subClient redis error:', error);
});
subClient.on('connect', () => console.log('subClient redis is connected'));
subClient.on('reconnecting', () => console.log('subClient redis is reconnecting'));
subClient.on('ready', () => console.log('subClient redis is ready'));
await pubClient.connect()
await subClient.connect()
this.adapterConstructor = createAdapter(pubClient, subClient);
} catch(err){
console.log(err)
}
}
@djdabs try this: https://github.com/redis/node-redis/issues/2443#issuecomment-1573393354
@djdabs try this: #2443 (comment)
Still getting a triggerUncaugthException after client connects -> attempts to reconnect, but I'm now getting a different error.
fwiw, i don't think i need a pingInterval with GCP. Their docs say by default no idle timeout is configured. https://cloud.google.com/memorystore/docs/redis/supported-redis-configurations#modifiable_configuration_parameters
Error: write EPIPE
at afterWriteDispatched (node:internal/stream_base_commons:160:15)
at writeGeneric (node:internal/stream_base_commons:151:3)
at Socket._writeGeneric (node:net:930:11)
at Socket._write (node:net:942:8)
at doWrite (node:internal/streams/writable:411:12)
at clearBuffer (node:internal/streams/writable:572:7)
at Writable.uncork (node:internal/streams/writable:351:7)
at Immediate._onImmediate (/usr/src/app/node_modules/@redis/client/dist/lib/client/socket.js:84:69)
at process.processImmediate (node:internal/timers:476:21) {
resolved my issue.. after switching to ioredis the error message got more specific and I was able to track down the underlying problem (redis required TLS). Disabled TLS on memorystore and it was able to work now.
redis error: ParserError: Protocol error, got "\u0015" as reply type byte. Please report this
Are there any updates on this issue? I'm currently facing the same problem while using a Redis instance served by Digital Ocean. TLS is in place and the job is listening on "error" - each time the issue occurs, I reset the connection. I don't know if it is the best solution but it kind of works even if it throws the error every five minutes.
In the previous comments, there is a suggestion that pings the server. Do you think that is the best way to handle it at the moment? Or should we wait the patch?
@stefanodecillis You can just use pingInterval
since #2524 is fixed in version redis@4.6.8
Getting the same error at v4.6.12 `const redis = require('redis'); require('dotenv').config(); const client = redis.createClient({ url: process.env.KV_URL }); (async () => { await client.connect(); })(); client.on('connect', () => { console.log('Connected to Redis'); });
client.on('error', (err) => {
console.error(Redis Error: ${err}
);
});
client.on('reconnecting', () => console.log('client is reconnecting')); client.on('ready', () => console.log('client is ready'));
module.exports = client;`
This is the error im gettting
ERROR Redis Error: Error: Socket closed unexpectedly INFO client is reconnecting INFO Connected to Redis ERROR Redis Error: Error: Socket closed unexpectedly ERROR Redis Error: Error: Socket closed unexpectedly INFO client is reconnecting INFO Connected to Redis ERROR Redis Error: Error: Socket closed unexpectedly ERROR Redis Error: Error: Socket closed unexpectedly Task timed out after 10.02 seconds
It runs well on local but not when deployed on vercel
We are experiencing the same issue. We're listening error events explicitly...our connection logic is below @leibale :
export const createRedisClient = (options: RedisClientOptions) => {
const client = createClient(options);
client.on('error', async error => {
console.error(`Redis client error : ${error}`);
Sentry.captureException(error); // Capture the error with Sentry
if (
error.code === 'ECONNRESET' ||
error.code === 'EPIPE' ||
error.code === 'ECONNREFUSED'
) {
// Disconnect before attempting to reconnect
await client.disconnect();
client.connect().catch(err => {
console.error(`Failed to reconnect redis client: ${err}`);
Sentry.captureException(err); // Capture the reconnection error with Sentry
});
}
});
client.connect().catch(err => {
console.error(`Failed to connect redis client: ${err}`);
Sentry.captureException(err); // Capture the reconnection error with Sentry
});
return client;
};
The error message indicates that Redis is running in protected mode due to enabled protected mode and the absence of a password for the default user. In this mode, connections are only accepted from the loopback interface. To enable connections from external computers, you can choose one of the following solutions:
Disable protected mode by executing the command: 'CONFIG SET protected-mode no'.
Good day! The socket connection closes unexpectedly and doesn't reconnect, my older version of node-redis(2.8.0) was reconnecting fine and still does. After reconnect it doesn't print ready anymore. We are using AWS ElastiCache. I can only reproduce this on production env. We have a package that wraps node-redis and is used in all our apps, so I don't think is related to version difference. I tried to comment out next code and it doesn't close the connection at all (from @socket.io/redis-adapter).
Here is where I catch the parser error: client/socket.ts
List with buffers and offsets:
Code for creating the client
Environment: