# Bug in node.send?

**URL:** <https://discourse.nodered.org/t/bug-in-node-send/11177>\
**Category:** General\
**Created:** [15 May 2019 18:20 UTC](https://discourse.nodered.org/t/bug-in-node-send/11177 "2019-05-15T18:20:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Albatroz](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@Albatroz](https://discourse.nodered.org/u/Albatroz)\
**Post date:** [15 May 2019 18:20 UTC](https://discourse.nodered.org/t/bug-in-node-send/11177/1 "2019-05-15T18:20:36Z")

</div>

I created a stream where the message goes through a loop and inside the loop I make a node.send on each iteration for the next node to store the information in the file, however the information is repeated several times in the file, as can be seen in debug. I made an example model to illustrate my problem, as follows:

```auto
[{"id":"4102703d.b8d97","type":"function","z":"f800399f.f91e98","name":"","func":"let test = [0,1,2,3,4,5,6,7,8,9,10]\n\nfor(let i in test){\n msg.payload = test[i]\n node.send(msg)\n}\n\nreturn\n","outputs":1,"noerr":0,"x":1570,"y":360,"wires":[["a3ff2780.a7cb88"]]},{"id":"3a6a3bac.bcd8e4","type":"inject","z":"f800399f.f91e98","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"300","x":1340,"y":360,"wires":[["4102703d.b8d97"]]},{"id":"a3ff2780.a7cb88","type":"iconvfile-out","z":"f800399f.f91e98","name":"","filename":"test","appendNewline":true,"createDir":false,"overwriteFile":"false","charset":"UTF-8","x":1790,"y":320,"wires":[["24447700.93a97a"]]},{"id":"24447700.93a97a","type":"debug","z":"f800399f.f91e98","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1950,"y":320,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![moebius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/moebius/32/2872_2.png) [@moebius](https://discourse.nodered.org/u/moebius)\
**Post date:** [15 May 2019 18:26 UTC](https://discourse.nodered.org/t/bug-in-node-send/11177/2 "2019-05-15T18:26:21Z")

</div>

I guess you change the same msg in every iteration - clone the msg before altering it.

`RED.util.cloneMessage(msg);`

---

<div class="post-metadata">

**Author:** ![Albatroz](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@Albatroz](https://discourse.nodered.org/u/Albatroz)\
**Post date:** [15 May 2019 19:02 UTC](https://discourse.nodered.org/t/bug-in-node-send/11177/3 "2019-05-15T19:02:45Z")

</div>

> [@moebius](#):
>
> RED.util.cloneMessage(msg);

Cloning the message as you suggested it works, but when using the node.send it would be advisable to clone the message to not have this type of problem?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [15 May 2019 19:18 UTC](https://discourse.nodered.org/t/bug-in-node-send/11177/4 "2019-05-15T19:18:16Z")

</div>

Cloning a message can take time and would not be necessary if you were generating new messages, so is not required in all cases. Thus we don’t mandate it.

---

<div class="post-metadata">

**Author:** ![nileio](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nileio/32/9444_2.png) [@nileio](https://discourse.nodered.org/u/nileio)\
**Post date:** [16 August 2019 04:11 UTC](https://discourse.nodered.org/t/bug-in-node-send/11177/5 "2019-08-16T04:11:45Z")

</div>

hi @dceejay - sorry to revive this thread, but could you pls confirm if `node.send(msg)` clones the message in the latest version by default ? my current tests "suggest" that the behavior of `node.send(msg)` clones the message regardless. In my custom node i would like to control the cloning of `msg` myself and so do not want to add an extra overhead by a redundant clone operation.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [16 August 2019 06:01 UTC](https://discourse.nodered.org/t/bug-in-node-send/11177/6 "2019-08-16T06:01:20Z")

</div>

If there is only one output or only one wire attached it doesn't clone. I.E. the first wire isn't cloned. The rest are.

---

<div class="post-metadata">

**Author:** ![nileio](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nileio/32/9444_2.png) [@nileio](https://discourse.nodered.org/u/nileio)\
**Post date:** [19 August 2019 04:41 UTC](https://discourse.nodered.org/t/bug-in-node-send/11177/9 "2019-08-19T04:41:07Z")

</div>

@dceejay thanks for clarifications..
