feathersjs-ecosystem / feathers-sync

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

Subscribe to Redis messages after Redis client connects. Subscribing … #179

Closed babysealclubber closed 2 years ago

babysealclubber commented 2 years ago

…before connection causes _RedisCommandsQueue_pubSubState in node-redis 4.x to get set resulting in 'AuthError: Cannot send commands in PubSub mode' error.

Summary

This is a fix to https://github.com/feathersjs-ecosystem/feathers-sync/issues/178

When a password is set on the redis server the following error is thrown by node-redis 4.x: AuthError: Cannot send commands in PubSub mode

This happens because there is an internal state(_RedisCommandsQueue_pubSubState) in node-redis that gets set when the redis client .subscribe() method is called that will cause a subsequent call to the client .connect() method to fail with the aforementioned AuthError. I don't know if this is really an issue with node-redis or if it's user error but performing .subscribe() post .connect() in the ready Promise of feathers-sync gets around the issue.