lisk-sdk icon indicating copy to clipboard operation
lisk-sdk copied to clipboard

Avoid Event Missusages

Open pablitovicente opened this issue 5 years ago • 2 comments

Expected behavior

We need to make sure events are used for its intended purpose only; currently different modules could be using registered events passing different event.data causing the subscribers to get more than one event and potentially causing unexpected side effects in different modules. We should also probably document what's the intended use for existing events.

Actual behavior

Events can be fired with different data and subscriber can potentially behave erratically

Steps to reproduce

  • Emit a registered event that's in use and send random data or data that's not the expected by the subscribers

Which version(s) does this affect? (Environment, OS, etc...)

pablitovicente avatar May 07 '19 15:05 pablitovicente

I think event name needs to be cleaned up and make it more clear what is publishing. Instead of block:change we should publish newBlock or deleteBlock etc

shuse2 avatar May 07 '19 18:05 shuse2

Example pseudo-stack which might cause failures

Original Stack:

  1. FileA.js -> channel.subscribe('event:xyz', cb);
  2. FileB.js -> channel.publish('event:xyz', { foo: 'bar', value: 42});
  3. FileA.js -> executes actions expecting { foo: 'bar', value: 42}

All good so far

New Stack due to someone reusing an existing event:

  1. FileA.js -> channel.subscribe('event:xyz', cb);
  2. FileC.js -> channel.publish('event:zyz', ['radio', 'head', 'pearl', 'jam']);
  3. FileB.js -> channel.publish('event:xyz', { foo: 'bar', value: 42});
  4. FileA.js -> executes actions expecting { foo: 'bar', value: 42} but first gets ['radio', 'head', 'pearl', 'jam']

As the subscriber is probably expecting an schema the new first publishing to event:zyz with different schema will make it fail.

pablitovicente avatar May 08 '19 08:05 pablitovicente

Closing this issue for no activity and value added is small

shuse2 avatar Dec 20 '23 16:12 shuse2