Hi! We just set up redis on fly.io via this tutorial.
We are consistently seeing this error:
2023-07-17T03:56:09Z app[91857315f11298] sjc [info]Redis Client Error SocketClosedUnexpectedlyError: Socket closed unexpectedly
2023-07-17T03:56:09Z app[91857315f11298] sjc [info] at Socket.<anonymous> (/home/node/node_modules/@redis/client/dist/lib/client/socket.js:195:118)
2023-07-17T03:56:09Z app[91857315f11298] sjc [info] at Object.onceWrapper (node:events:627:26)
2023-07-17T03:56:09Z app[91857315f11298] sjc [info] at Socket.emit (node:events:512:28)
2023-07-17T03:56:09Z app[91857315f11298] sjc [info] at Socket.emit (node:domain:489:12)
2023-07-17T03:56:09Z app[91857315f11298] sjc [info] at TCP.<anonymous> (node:net:334:12)
2023-07-17T03:56:09Z app[91857315f11298] sjc [info]Connected!
The client connects again soon after but not before our server returns an error response on the incoming HTTP request.
Question: Is the socket closing expected behavior (and I need to ping the redis client periodically to keep the connection alive), or am I missing something in the setup?
Setup:
We are connecting to redis deployed on fly.io with node also on fly.io
redis.ts:
import { createClient } from 'redis';
const redisClient = createClient({
url: process.env.REDIS_URL,
# REDIS_URL='redis://default:password@fly-kino-redis-dev.upstash.io'
socket: {
family: 6
}
});
redisClient.on('error', err => console.log('Redis Client Error', err));
redisClient.on('connect', () => console.log('client is connect'));
redisClient.on('reconnecting', () => console.log('client is reconnecting'));
redisClient.on('ready', () => { console.log('Connected!'); });
export default redisClient
export function closeInstance() {
redisClient.quit()
}
and in our server.ts:
import app from './app' # all other app setup & routing done here
import redisClient from './redis';
const port = process.env.PORT || 3000;
(async () => {
await redisClient.connect();
})();
app.listen(port, () => console.log(`Hello World! We are on port ${port}!!`))
redis package version:
"redis": "^4.6.7",