parse-community / parse-community/parse-server

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

Open
#8,705 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

state:released state:released-alpha state:released-beta
Dominant language
JavaScript
Stars
21.4k
Forks
4.8k
Avg merge
7h 45m
Merged PRs (30d)
11

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating Parse Server's Redis client creation and cache connection entry point, then reproduce the Digital Ocean disconnect behavior with the versions and stack trace described. Verify that the client handles error, connect, reconnecting, and ready events without stopping cache use; done means unexpected disconnects recover and subsequent cache operations continue normally.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, redis
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.