feathersjs-ecosystem / feathers-sync

Synchronize service events between Feathers application instances
MIT License
221 stars 41 forks source link

[Help Wanted] Events are not sent to all instances always #165

Closed koraniar closed 2 years ago

koraniar commented 3 years ago

Steps to reproduce

I am creating two Workers using cluster, the Main thread does not expose a port, just controls the Workers

I used the basic implementation of this library, I configure it in the app.js file in this way:

const redisUrl = app.get('redisUrl'); // redis://127.0.0.1:6379
app.configure(sync({
  uri: redisUrl,
}));
if (cluster.isMaster) {
  app.removeAllListeners('sync-in');
}

In the Index.js file, I expose the port of the workers when the connection is ready in this way:

app.sync.ready.then(() => {
  const port = app.get('port');

  const server = app.listen(port);
  server.on('listening', () => logger.info(`WORKER #${cluster.worker.id} - Feathers application started on %s:%d`, app.get('host'), port));
});

Additionally, I put this log inside the channels.js in this way:

app.service('executions').publish((data) => {
  console.log(`WORKER #${cluster.worker.id}`, data);
});

When I update two registries (each register from a different client) using the patch method over a table called "executions" I get the following output:

WORKER #2 - Feathers application started on localhost:3030
WORKER #1 - Feathers application started on localhost:3030

WORKER #1 { id: '84a6f208-8a23-41c2-beb2-73fe65056c19',
  deviceName: 'ESTEBANSVM-W10' }

WORKER #2 { id: 'b5fd3369-42c7-4584-b472-767788fbef17',
  deviceName: 'Esteban’s MacBook Pro' }
WORKER #1 { id: 'b5fd3369-42c7-4584-b472-767788fbef17',
  deviceName: 'Esteban’s MacBook Pro' }

Repeating the process (without restarting the server) I get this output:

serviceName WORKER #1 executions { id: 'f4ac27ef-2dde-4fa5-a8da-0c16f1346dca',
  deviceName: 'Esteban’s MacBook Pro' }

serviceName WORKER #2 executions { id: 'eb859e30-1cad-4d1e-b395-769e2642da43',
  deviceName: 'ESTEBANSVM-W10' }
serviceName WORKER #1 executions { id: 'eb859e30-1cad-4d1e-b395-769e2642da43',
  deviceName: 'ESTEBANSVM-W10' }

And repeating it again (without restarting the server) I get this output:

serviceName WORKER #1 executions { id: '9e124387-9086-40a8-90b6-3edc90355fbf',
  deviceName: 'Esteban’s MacBook Pro' }

serviceName WORKER #2 executions { id: 'b8b710a5-42ac-4843-ae4e-c49da16bc021',
  deviceName: 'ESTEBANSVM-W10' }

Expected behavior

The event should send to all the instances always.

Actual behavior

Sometimes, the event is sent to all instances, sometimes the event is not sent to any instance, and sometimes the event is sent to some instances.

System configuration

Module versions (especially the part that's not working):

NodeJS version: 10.19.0

Operating System: Mac OS 11.2.3 (Big Sur)

Browser Version: Chrome 90.0.4430.93

daffl commented 2 years ago

This module is intended to be used with Feathers v4 and later. Please upgrade to the current version and reopen if the problem persists.