-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Duplicated payload from gprc-call #15
Comments
Odd. This is starting to look like a node-red bug. Wrote a very simple node plugin that duplicates my very simple function node, and the two behave very differently. The simple function (no grpc involved) sends unique message to debug, but wrapping the same logic in a custom node does not: displays the same behavior I am seeing with the grcp nodes, the same msg.payload multiple times. I will reach out to the node-red community and follow up. |
Hi Jeff, This is a Javascript basic problem, what you're running into is called closure inside a loop problem. The difference between the function node and the wrapper node is that with the function node, the msg gets cloned upon arriving to the debug node. Meanwhile, the wrapper node just call the callback with the same msg object. Put it simple, the callbacks are put in the runtime's event queue and when all of them are executed, the msg object has been changed to reflect the last value of the loop. |
You can try this:
|
That makes sense, however, it does not solve the issue - I tried it in the simple node and still the debug node is only seeing that last msg.payload. The closure is itself both initialized and resolved in the for loop, so it makes no difference. So far the only thing that resolves the issue is cloning the msg (my original "fix" did as well, but as you pointed out it was not flow-friendly). Came across this article that sums it up: https://nodered.org/blog/2019/09/13/cloning-messages |
When testing a simple gPRC method that takes a non-streaming request but returns a streaming response, the gprc-call node is returning only the last payload sent by the server.
gprc-call-dups.txt
I believe this is due to gprc-call.js sending messages with identical _msgid; perhaps node-red is cacheing things? Anywho, I can submit a patch to fix.
The text was updated successfully, but these errors were encountered: