# Behavior of websocket handleServerUpgrade

**URL:** https://discourse.nodered.org/t/behavior-of-websocket-handleserverupgrade/32934
**Category:** Developing Nodes
**Created:** [16 September 2020 01:50 UTC](https://discourse.nodered.org/t/behavior-of-websocket-handleserverupgrade/32934 "2020-09-16T01:50:16Z")
**Posts on this page:** 7
**Page:** 1

<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 September 2020 01:50 UTC](https://discourse.nodered.org/t/behavior-of-websocket-handleserverupgrade/32934/1 "2020-09-16T01:50:16Z")

</div>

Hi all,  
I am building a new node and was learning about the way the core websocket nodes are built.  
I created a websocket listener for some test paths, examples  
`/test1` and `/test2`  
I used them for testing and then I deleted those listeners from the node configuration and restarted node-red.

Now my expectations is that those listeners should be gone for good but I noticed that the function  
`handleServerUpgrade` used in 22-websocket.js is still gets called for those deleted paths. I have no clue on how it is still referencing those deleted paths.

See below..  
I just inserted a console.log in place below and my console showed repeatedly  
here is the function from 22-websocket.js

```auto
    function handleServerUpgrade(request, socket, head) {

        const pathname = url.parse(request.url).pathname;
        console.log('handleServerUpgrade for ' + pathname);
        if (listenerNodes.hasOwnProperty(pathname)) {
            listenerNodes[pathname].server.handleUpgrade(request, socket, head, function done(ws) {
                listenerNodes[pathname].server.emit('connection', ws, request);
            });
        } else {
            // Don't destroy the socket as other listeners may want to handle the
            // event.
        }
    }

```

this is what I see on the console log. continuously the below lines are printed.

> handleServerUpgrade for /test1  
> handleServerUpgrade for /test2  
> handleServerUpgrade for /test1  
> handleServerUpgrade for /test2

Any thoughts about the reason why this is happening ? Am I missing something ?  
Could the reason be that we don't destroy the socket?  
Thank you

---

<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 September 2020 08:14 UTC](https://discourse.nodered.org/t/behavior-of-websocket-handleserverupgrade/32934/2 "2020-09-16T08:14:42Z")

</div>

You have deleted the node - but have you deleted the config node as well ?  
menu - configuration nodes - unused

---

<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 September 2020 09:23 UTC](https://discourse.nodered.org/t/behavior-of-websocket-handleserverupgrade/32934/3 "2020-09-16T09:23:49Z")

</div>

@dceejay Thank you! I am glad I asked the question. I had to delete the config node from the Configuration List found on the side bar only.  
What I actually initially did when deleting those config nodes, is used the Edit button next to the Path field from the websocket-in node config, and then the Delete button on the top bar of the config node! This has removed it from the list and so I assumed the config nodes were gone. This is what I become used to in all other nodes I suppose.  
I did not realise that the config node still exist there actually ! Thanks for pointing out . this is little different than what I expected when I deleted the config node though !

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [16 September 2020 09:38 UTC](https://discourse.nodered.org/t/behavior-of-websocket-handleserverupgrade/32934/4 "2020-09-16T09:38:48Z")

</div>

> [@nileio](#):
>
> What I actually initially did when deleting those config nodes, is used the Edit button next to the Path field from the websocket-in node config, and then the Delete button on the top bar of the config node! This has removed it from the list and so I assumed the config nodes were gone. This is what I become used to in all other nodes I suppose.

And that will have deleted the config nodes - there's nothing particular about the websocket nodes to behave differently in that regard.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [16 September 2020 09:52 UTC](https://discourse.nodered.org/t/behavior-of-websocket-handleserverupgrade/32934/5 "2020-09-16T09:52:46Z")

</div>

You can delete it by selecting in the Config nodes panel on the rhs and then clicking Delete key.  
For the future you can tell that you have unused config nodes as when you deploy, in the popup that appears saying successfully deployed there is a message telling you that you have some unused, and a link to click that will take you straight there.

---

<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 September 2020 10:08 UTC](https://discourse.nodered.org/t/behavior-of-websocket-handleserverupgrade/32934/6 "2020-09-16T10:08:19Z")

</div>

@knolleary Just made a few tests and you are right there nothing different than the others.. I "think" where the confusion came from at the start is because the node has two modes "Listen" and "Connect To" and each one has different configuration but it is shown from the same screen. I might have got confused or so for some reason , but I use the two modes for web socket in, and web socket out all around ..  
In all cases, all good now .. thanks for reply!

---

<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: [30 September 2020 10:08 UTC](https://discourse.nodered.org/t/behavior-of-websocket-handleserverupgrade/32934/7 "2020-09-30T10:08:25Z")

</div>

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