Skip to content

Scaling with redis gives wrong presence user list #273

@WillRy

Description

@WillRy

Reverb Version

^1.0

Laravel Version

^11.9

PHP Version

8.3

Description

When using the "scaling" mode of "reverb" using "redis", when creating a "loadbalancer" to distribute the load between several servers, the list of active users in the channels does not work correctly.

If the user is being served by server A, he will only be able to see the presence of users connected to this server, he will not be able to see the presence of users in the same channel, but connected to server B.

Example:
In this example below, the "here" method will only return active connections on the same server that the user is connected to. It is impossible to see all online users across the cluster. I believe that it is necessary for Laravel to adopt an active session control through redis, as suggested by socket.io:

https://github.com/socketio/socket.io/blob/main/examples/private-messaging/server/sessionStore.js#L30

Echo.join('online')
            .here((users) => {
                console.log('here', users);

           
               
            })
            .joining((user) => {
                console.log('joining', user);

              
            })
            .leaving((user) => {
                console.log('leaving', user);

              
            })
            .error((error) => {
                console.error('error', error);
            });

Steps To Reproduce

To reproduce:

  • Enable "scaling" mode
  • Configure Redis in .env
  • Configure 2 instances of Reverb running
  • Apply a load balancer to connect to these two instances
  • Connect the user to a channel and you will see the problem

In "here" method you will see the problem

Echo.join('online')
            .here((users) => {
                console.log('here', users);

           

            })
            .joining((user) => {
                console.log('joining', user);

              
            })
            .leaving((user) => {
                console.log('leaving', user);

              
            })
            .error((error) => {
                console.error('error', error);
            });

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions