abreits / node-red-contrib-amqp

Node-RED AMQP input and output nodes
16 stars 18 forks source link

node-red crashes when two or more branches are configured after amqp in #32

Open mtorre-iot opened 4 years ago

mtorre-iot commented 4 years ago

I am using amqp node. It works ok (both amqp in and out). The error happens when create more than one branch after amqp in.

When I do that, node-red simply crashes dumping the following text:

16 Feb 08:18:23 - [info] Starting flows 16 Feb 08:18:23 - [info] Started flows 16 Feb 08:18:23 - [info] [amqp-server:6721fcee.728ce4] Initializing in-clear AMQP connection 16 Feb 08:18:23 - [info] [amqp-server:6721fcee.728ce4] Connected to AMQP server amqp://localhost:5672?heartbeat=30 FATAL ERROR: v8::Object::SetInternalField() Internal field out of bounds 1: 0x9dab80 node::Abort() [node-red] 2: 0x9dbd36 node::OnFatalError(char const, char const) [node-red] 3: 0xb3b22a v8::Utils::ReportApiFailure(char const, char const) [node-red] 4: 0xebd6cc v8::internal::Object::SetPropertyWithAccessor(v8::internal::LookupIterator, v8::internal::Handle, v8::Maybe) [node-red] 5: 0xedae0b v8::internal::Object::SetPropertyInternal(v8::internal::LookupIterator, v8::internal::Handle, v8::Maybe, v8::internal::StoreOrigin, bool) [node-red] 6: 0xedaf73 v8::internal::Object::SetProperty(v8::internal::LookupIterator, v8::internal::Handle, v8::internal::StoreOrigin, v8::Maybe) [node-red] 7: 0x100b224 v8::internal::Runtime::SetObjectProperty(v8::internal::Isolate, v8::internal::Handle, v8::internal::Handle, v8::internal::Handle, v8::internal::StoreOrigin, v8::Maybe) [node-red] 8: 0x100c94a v8::internal::Runtime_SetKeyedProperty(int, unsigned long, v8::internal::Isolate*) [node-red] 9: 0x1376519 [node-red] Aborted (core dumped)

Environment: Ubuntu 18.04 Node 12.15.0 npm 6.13.4 node-red 1.0.3 node-red-contrib-amqp 1.0.2

mtorre-iot commented 4 years ago

I think i solved (or at least made a workaround). the full message coming from the amqplib cannot be transmitted as amqpMessage by the node.

in file: src/node/nodejs/amqp.js Original: node.initialize = function () { function Consume(msg) { node.send({ topic: node.topic || msg.fields.routingKey, payload: msg.getContent(), amqpMessage: msg }); }

proposed workaround:

node.initialize = function () { function Consume(msg) { var amqpm = new Object(); amqpm.fields = msg.fields; amqpm.payload = msg.getContent(); node.send({ topic: node.topic || msg.fields.routingKey, payload: amqpm.payload, //amqpMessage: msg amqpMessage: amqpm }); }

chulanovskyi-bs commented 3 years ago

I think i solved (or at least made a workaround). the full message coming from the amqplib cannot be transmitted as amqpMessage by the node.

in file: src/node/nodejs/amqp.js Original: node.initialize = function () { function Consume(msg) { node.send({ topic: node.topic || msg.fields.routingKey, payload: msg.getContent(), amqpMessage: msg }); }

proposed workaround:

node.initialize = function () { function Consume(msg) { var amqpm = new Object(); amqpm.fields = msg.fields; amqpm.payload = msg.getContent(); node.send({ topic: node.topic || msg.fields.routingKey, payload: amqpm.payload, //amqpMessage: msg amqpMessage: amqpm }); }

Hi! I've just ran into the same problem, but I'm not doing the same thing:

...create more than one branch after amqp in.

Moreover, I've tried just with the debug node, but it still throws the same error right at the time it consumes the message from queue image

Not sure if it's somehow related to the core of the problem - I'm using the RabbitMq server as a docker service:

  oc-rabbit:
    image: rabbitmq:3-management-alpine
    container_name: oc-rabbit

Tried also different node versions for my app (12.14.0, 12.16.2, 12.20) - didn't help.


Anyway, your solutions seems to be working, but I had to parse it a bit, 'cause of the formatting errors (because you posted it as a one-liner):

node.initialize = function () {
    if (node.server.prefetch) {
        function Consumeack(msg) {
            var amqpm = {};
            amqpm.fields = msg.fields;
            amqpm.payload = msg.getContent();
            node.send({
                topic: node.topic || msg.fields.routingKey,
                payload: msg.getContent(),
                amqpfields: msg.fields,
                amqpMessage: amqpm
            });
...

I'm wondering if those amqpfields and amqpMessage properties are really necessary?