Skip to content

Latest version of Redis won't automatically reconnect without error handling #8705

Open
@Vortec4800

Description

@Vortec4800

New Issue Checklist

Issue Description

I'm using a Redis Server hosted by Digital Ocean, and it disconnects every so often for whatever reason. With Redis 3.x this wasn't a big deal, the client would automatically reconnect. With Redis 4.x, you get an error in the console that complains about the lack of error handling.

It appears that added (even empty) event handlers during client creation is enough to bring back the behavior of Redis 3. I will create a PR with this change for reference.

Environment

Server

  • Parse Server version: 6.2.1
  • Operating system: Ubuntu 20 LTS
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): Digital Ocean

Logs

Before PR change:

node:events:492
      throw er; // Unhandled 'error' event
      ^

SocketClosedUnexpectedlyError: Socket closed unexpectedly
    at TLSSocket.<anonymous> (/var/parse/parse-server/node_modules/@node-redis/client/dist/lib/client/socket.js:182:118)
    at Object.onceWrapper (node:events:629:26)
    at TLSSocket.emit (node:events:526:35)
    at node:net:323:12
    at TCP.done (node:_tls_wrap:588:7)
Emitted 'error' event on Commander instance at:
    at RedisSocket.<anonymous> (/var/parse/parse-server/node_modules/@node-redis/client/dist/lib/client/index.js:339:14)
    at RedisSocket.emit (node:events:514:28)
    at RedisSocket._RedisSocket_onSocketError (/var/parse/parse-server/node_modules/@node-redis/client/dist/lib/client/socket.js:205:10)
    at TLSSocket.<anonymous> (/var/parse/parse-server/node_modules/@node-redis/client/dist/lib/client/socket.js:182:107)
    at Object.onceWrapper (node:events:629:26)
    [... lines matching original stack trace ...]
    at TCP.done (node:_tls_wrap:588:7)

Node.js v18.17.0

(Redis client does not reconnect after this message appears in the console, later errors show client is closed when the cache attempts to be used)

PR change adds the following handlers:

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

After PR change:

On initial launch, showing client creation and connection:

Parse Redis client is connected
Parse Redis client is connected
Parse Redis client is ready
Parse Redis client is ready
Parse Redis client is connected
Parse Redis client is ready

When a disconnect happens:

Parse Redis client error SocketClosedUnexpectedlyError: Socket closed unexpectedly
    at TLSSocket.<anonymous> (/var/parse/parse-server/node_modules/@node-redis/client/dist/lib/client/socket.js:182:118)
    at Object.onceWrapper (node:events:629:26)
    at TLSSocket.emit (node:events:526:35)
    at node:net:323:12
    at TCP.done (node:_tls_wrap:588:7)
Parse Redis client is reconnecting
Parse Redis client is connected
Parse Redis client is ready

Future disconnects repeat the same message, showing the connection gets closed but then reopens and everything continues to work normally.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions