pnxtech / hydra

A light-weight library for building distributed applications such as microservices
https://www.hydramicroservice.com
MIT License
645 stars 54 forks source link

_sendMessage may have a possible silent failure #174

Closed sjmcdowall closed 6 years ago

sjmcdowall commented 6 years ago

Looking at the _sendMessage code .. I think we have a corner case condition where we can silently fail to send a message ..

Use Case: Invoke sendMessage with an invalid (or dead) specific instance ID .

https://github.com/flywheelsports/hydra/blob/master/index.js#L1385


L1385          if (instance && instance !== '') {
            this._sendMessageThroughChannel(`${mcMessageKey}:${serviceName}:${instance}`, message);
          } else {

The code appears to blindly accept the instance given .. even if it is either totally bogus or not - running. It seems to be there should be a check before the _sendMTC to see if the instance is actually in the array returned from _getServicePresence() and if not, invoke reject()

cjus commented 6 years ago

@sjmcdowall you are correct. The instances value here should be used to confirm an instance is available - if indeed the message in question directly references an instanceID in the UMF message to field. Otherwise, any available instance should be used.

https://github.com/flywheelsports/hydra/blob/master/index.js#L1378

sjmcdowall commented 6 years ago

Fixed by https://github.com/flywheelsports/hydra/pull/182