# Need help resolviing an issue for a custom node

**URL:** <https://discourse.nodered.org/t/need-help-resolviing-an-issue-for-a-custom-node/23993>\
**Category:** Developing Nodes\
**Created:** [31 March 2020 19:19 UTC](https://discourse.nodered.org/t/need-help-resolviing-an-issue-for-a-custom-node/23993 "2020-03-31T19:19:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)\
**Post date:** [31 March 2020 19:19 UTC](https://discourse.nodered.org/t/need-help-resolviing-an-issue-for-a-custom-node/23993/1 "2020-03-31T19:19:07Z")

</div>

I started creating a set of ICMP tools for listening/sending messages/packets.  
So the node is based around the npm package [ICMP](https://www.npmjs.com/package/icmp).  
On some deploys listen node works successfully, but on some deploys, the node is just stuck, I have a detailed explanation on GitHub with screenshots and possibly the main error that someone more experienced than me should look at it.

[Link to the repo](https://github.com/vukmirovic98/node-red-contrib-icmp/)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [31 March 2020 19:59 UTC](https://discourse.nodered.org/t/need-help-resolviing-an-issue-for-a-custom-node/23993/2 "2020-03-31T19:59:42Z")

</div>

Does that happen (more) after repeated deploys?

---

<div class="post-metadata">

**Author:** ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)\
**Post date:** [31 March 2020 20:00 UTC](https://discourse.nodered.org/t/need-help-resolviing-an-issue-for-a-custom-node/23993/3 "2020-03-31T20:00:51Z")

</div>

well sometimes it happens right when i start node-red , i inserted it now in a function and i am calling a function it looks okay for now...

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [31 March 2020 20:23 UTC](https://discourse.nodered.org/t/need-help-resolviing-an-issue-for-a-custom-node/23993/4 "2020-03-31T20:23:15Z")

</div>

> [@lizzardguki](#):
>
> On some deploys listen node works successfully,

Hi Vukmirovic,

I see this on your readme page: "_When i ping localhost , the listen nodes receives two pings back with completly same output_".

I haven't looked at your code in detail, but I had this kind of issues multiple times in the past...  
You start listening to the packets, as soon as your node starts.  
When you deploy your flow, your node starts again so your start listening again to the packets.  
So now you have two listeners for the same packets, so your listeners will be called _ **twice** _.  
And so on...

Could that be your issue perhaps?  
If so, you should stop listening for packets as soon as your node is [closed](https://nodered.org/docs/creating-nodes/node-js#closing-the-node) (at a deploy).  
Something like this:

```auto
node.on('close', function() {
    // Stop listening for packets
    icmp.close()
});

```

Bart

---

<div class="post-metadata">

**Author:** ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)\
**Post date:** [31 March 2020 21:22 UTC](https://discourse.nodered.org/t/need-help-resolviing-an-issue-for-a-custom-node/23993/5 "2020-03-31T21:22:10Z")

</div>

Well i think natuarly when pinging localhost that should happen because when :  
0. ICMP is listening for ping.

1. I ping localhost. (listen node sends output) icm protocol returns answer.
2. icmp listen is returning the answer as second message  
The node.on close does help fix some issues , will test it further in the morning...

---

<div class="post-metadata">

**Author:** ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)\
**Post date:** [1 April 2020 20:45 UTC](https://discourse.nodered.org/t/need-help-resolviing-an-issue-for-a-custom-node/23993/6 "2020-04-01T20:45:25Z")

</div>

Added ICMP.close, when starting node-red sometimes it works right at the start , sometimes it needs to be redeployed,when you have time please check it out. I updated the repo.

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [1 April 2020 21:19 UTC](https://discourse.nodered.org/t/need-help-resolviing-an-issue-for-a-custom-node/23993/7 "2020-04-01T21:19:05Z")

</div>

> [@lizzardguki](#):
>
> when you have time please check it out

- See you call icmp.close at the end of the "input" event in the send.js file. Shouldn't you add there also a "close" event where you call icmp.close?
- I see you use the [https://www.npmjs.com/package/dns-lookup](https://www.npmjs.com/package/dns-lookup) library, which hasn't been maintained for more than 4 years. If I were you, I should try to find an actively maintained library ...

> [@lizzardguki](#):
>
> when starting node-red sometimes it works right at the start , sometimes it needs to be redeployed

No idea at first sight. Then I should have to debug, but other issues at the moment....  
Could it be that you start listening too soon perhaps? Because you start listening when the flow is still starting (i.e. as soon as your node is being started). Otherwise you shouldn't start listening automatically, but allow start/stop listening via an input message. When msg.payload=true then you start listening (if not listening already), and when msg.payload=false you stop listening (if listening currently). With a simple boolean you can remember whether you are listening or not...  
Then you can use an inject node that sends a message at startup automatically, to start listening. In that case you know at least that everything has been started already, before you start listening....

---

<div class="post-metadata">

**Author:** ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)\
**Post date:** [1 April 2020 21:43 UTC](https://discourse.nodered.org/t/need-help-resolviing-an-issue-for-a-custom-node/23993/8 "2020-04-01T21:43:00Z")

</div>

> Could it be that you start listening too soon perhaps? Because you start listening when the flow is still starting (i.e. as soon as your node is being started). Otherwise you shouldn't start listening automatically, but allow start/stop listening via an input message. When msg.payload=true then you start listening (if not listening already), and when msg.payload=false you stop listening (if listening currently). With a simple boolean you can remember whether you are listening or not...  
> Then you can use an inject node that sends a message at startup automatically, to start listening. In that case you know at least that everything has been started already, before you start listening....

I think that is a great solution , i too was woried that i was starting to listen too soon...  
I think i could use your solution or add a sort of double check function that will ping localhost to check if the icmp.listen is working properly.  
But as it is late and i need to get up early in the morning i will just write small ideas on a piece of paper for now , and hopefuly finish these nodes and publish them by the end of the week.

Once again thank you for your help!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [31 May 2020 21:43 UTC](https://discourse.nodered.org/t/need-help-resolviing-an-issue-for-a-custom-node/23993/9 "2020-05-31T21:43:03Z")

</div>

Closed on 31 May 2020 21:43 UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
