-
Notifications
You must be signed in to change notification settings - Fork 5
multiple messages in the same "on('data')" #20
Comments
Experimenting the same. It is enough a Bridge and one Node, shouting very quickly. For instance a "master" node shouts two messages very close to each other. The "plugin" node doesn't receive the payload, because the two payloads are concatenated and data is ignored due to: https://github.com/nkcmr/flic/blob/master/lib/bridge.js#L55. Notice
That should be two messages. Any idea? |
Script to reproduce the issue:
Set enviroment variable
Log.
Bridge receives invalid data because the three shouts are concatenated in one string and, when it is json parsed, an error is thrown. |
Debugging a bit more, and guessing about Then, stealing a snippet from that issue, I tested this one:
Result:
As in flic example above, I would expect three console logs, not only one. Maybe I am missing something here and I was wondering if, behind the scenes, flic behaviour is due to Node.js. I have not idea if that is expected or not. |
I am afraid that is expected and it is called "coalescing of TCP packets". See nodejs/node-v0.x-archive#15443 (comment) @nkcmr Thougths? |
After giving a look at If we send a message with a semantic structure, like json, we cannot rely on TCP to maintain the coherence of the message. It is explained very well in the comment link (node-v0.x archive) I provided above. I hope PR looks good for you. |
Thanks for the investigative work @albertosantini. Will publish a release to NPM with your changes. |
if there are three nodes sending messages at the same time to a single node, then while the first .on 'data' event is being handled, the other two messages are added to the stream, thus the next 'data' event will return a concatenated string, which will be ignored, because that can't be json parsed.
The text was updated successfully, but these errors were encountered: