balderdashy / balderdashy/sails

Sockets not stored in redis and onRedisDisconnect does not work

Open
#6,792 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

helpful info or workaround sockets
Dominant language
JavaScript
Stars
22.8k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Node version: 10.15.3
Sails version (sails): 1.2.3
ORM hook version (sails-hook-orm): 2.1.1
Sockets hook version (sails-hook-sockets): 2.0.0
Grunt hook version (sails-hook-grunt): 4.0.0


It seems that socket connecting to sails are not saved in redis, despite having that set up in config/sockets.js

On a fresh Sails.js installation (generated with sails new and option empty, my config/sockets.js looks like this:

module.exports.sockets = {
    
  adapter: 'socket.io-redis',
  url: 'redis://127.0.0.1:6379',

  onRedisDisconnect: function () {
    console.log("FOO!!!");
 };

If I now add "socket.io-redis": "~5.2.0", to package.json and run npm install I can lift my Sails app without problems. However, Sails doesn't store anything in redis. If I connect a socket and look into redis (via redis-cli) - it is empty. There is not a single database with a single key. Nothing.

Additionally, if I stop redis, I'll get

error: Redis socket "admin sub" server went offline...
error: Redis socket "admin pub" server went offline...
error: Redis socket "sub" server went offline...
error: Redis socket "pub" server went offline...

but onRedisDisconnect is obviously not called, I never get the console.log

My adapter settings are definitely used by Sails: If I change them to something nonsense, I'll get an error ("Failed to lift app: Error: Redis connection to 127.999.0.1:6379 failed - getaddrinfo ENOTFOUND 127.999.0.1 127.999.0.1:6379").
Same goes if redis is not running, when I try to start Sails.

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

Reproduce the issue from config/sockets.js using the socket.io-redis dependency added in package.json, then inspect Redis with redis-cli while connecting a socket and stopping Redis. Compare the observed Redis state and disconnect behavior with the expected socket storage and onRedisDisconnect callback, using the reported error messages as checkpoints for completion.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.