-
-
Notifications
You must be signed in to change notification settings - Fork 579
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
Actions in services with ProtoBuf and NATS cannot return 0 and false. #511
Comments
@AndreMaz could you help with it? |
@hoanganh25991 Could you check once? |
Hi @alvarocantador , In my test, I only use moleculer-cli to init minimal project template. Example ready to run: |
@icebob @hoanganh25991 In your case, the greeter is a local service and its work as expected. Try to run dev in a shell and call it in another repl, you will see undefined. I have the bug example here: https://github.com/alvarocantador/moleculer-zero-and-false-bug In this case I am using the moleculer-runner inside of a docker image, and via NATS in another broker, I am trying to call the |
Hi @alvarocantador , By default, broker config "prefer local", which lead to call without send through NATS. I digging in transporter & serializer code to figure out. |
Protobuf serialize flow:
I think the if check falsy value on
As what I test, remove the falsy check, response return false, 0 as expected https://github.com/moleculerjs/moleculer/blob/master/src/serializers/base.js#L98 Protobuf Serializerhttps://github.com/moleculerjs/moleculer/blob/master/src/serializers/protobuf.js Serializebase.js > serializeCustomFields
Falsy value not converted to string
case P.PACKET_RESPONSE: {
obj.meta = JSON.stringify(obj.meta);
if (obj.data) {
if (!obj.stream) {
obj.data = JSON.stringify(obj.data);
}
}
}
protobuf.js > serializeCustomFields
Buffer not built up
case P.PACKET_RESPONSE: {
if (obj.data && !obj.stream)
obj.data = Buffer.from(obj.data);
break;
} Deserializeprotobuf.js > deserializeCustomFields
No data key on obj, return undefined
case P.PACKET_RESPONSE: {
if (obj.data && !obj.stream) {
if (obj.data.length)
obj.data = obj.data.toString("utf8");
else
obj.data = undefined;
}
break;
} |
@hoanganh25991 good catch. Thank you, I'm fixing. |
I've fixed. @hoanganh25991 @alvarocantador could you check it to install master with |
Hi @icebob , I've tested your fix in "moleculerjs/moleculer" package, now Protobuf serialize correctly on false, 0 case. However, it return as "undefined" on null case. As my test above, on "greeter.willReturnNull", Protobuf deserialize as "undefined". Test example ready to run: |
Thanks. I'm checking... |
I've fixed it. |
Prerequisites
Please answer the following questions for yourself before submitting an issue.
Expected Behavior
Be able to receive
0
andfalse
as a result of some action in a service using NATS and Protobuf.Current Behavior
0 and false are received as undefined.
Failure Information
Protobuf serialize or deserialize the message incorrectly and turns
0
andfalse
results intoundefined
Steps to Reproduce
Reproduce code snippet
EXAMPLE READY TO RUN:
https://github.com/alvarocantador/moleculer-zero-and-false-bug
Context
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
Failure Logs
The text was updated successfully, but these errors were encountered: