# Node-red crashes on calling editor.stop()

**URL:** <https://discourse.nodered.org/t/node-red-crashes-on-calling-editor-stop/32449>\
**Category:** General\
**Created:** [4 September 2020 14:15 UTC](https://discourse.nodered.org/t/node-red-crashes-on-calling-editor-stop/32449 "2020-09-04T14:15:44Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![r0ller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/r0ller/32/14327_2.png) [@r0ller](https://discourse.nodered.org/u/r0ller)\
**Post date:** [4 September 2020 14:15 UTC](https://discourse.nodered.org/t/node-red-crashes-on-calling-editor-stop/32449/1 "2020-09-04T14:15:44Z")

</div>

Hi All,

I'm looking for an option to be able to disable/enable the editor on the fly so I thought about calling editor.stop() in a function node when I want to disable the editor (and later editor.start() to enable it). However, when stopping the editor, node-red crashes immediately. It might have to do something with the fact that I'm also communicating with node-red from the app via the http api but I thought that the editor and the runtime are separated. Besides that it does crash immediately so I don't think that any http api calls are involved.

That's what I get in the terminal:

4 Sep 16:04:36 - [warn] Communication send error: Error: WebSocket is not open: readyState 3 (CLOSED)  
4 Sep 16:04:37 - [red] Uncaught Exception:  
4 Sep 16:04:37 - TypeError: Cannot read property 'handleUpgrade' of null  
at Server.upgrade (/usr/local/lib/node\_modules/node-red/node\_modules/@node-red/editor-api/lib/editor/comms.js:204:30)  
at Server.emit (events.js:323:22)  
at onParserExecuteCommon (\_http\_server.js:642:14)  
at onParserExecute (\_http\_server.js:583:3)

Is this considered a bug? Any hints are welcome!

Best regards,  
r0ller

---

<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:** [4 September 2020 15:34 UTC](https://discourse.nodered.org/t/node-red-crashes-on-calling-editor-stop/32449/2 "2020-09-04T15:34:59Z")

</div>

What unpublished, internal API are you using to call `editor.stop()` from a Function node that doesn't have direct access to the internals of Node-RED?

---

<div class="post-metadata">

**Author:** ![r0ller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/r0ller/32/14327_2.png) [@r0ller](https://discourse.nodered.org/u/r0ller)\
**Post date:** [4 September 2020 15:50 UTC](https://discourse.nodered.org/t/node-red-crashes-on-calling-editor-stop/32449/3 "2020-09-04T15:50:02Z")

</div>

I simply required @node-red/editor-api in the functionGlobalContext section in settings.js, retrieved a reference to it in a variable (say editor) via global.get() as it is usually done in such cases and called editor.stop().

---

<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:** [4 September 2020 16:01 UTC](https://discourse.nodered.org/t/node-red-crashes-on-calling-editor-stop/32449/4 "2020-09-04T16:01:06Z")

</div>

Okay... lets take a step back.

> [@r0ller](#):
>
> I'm looking for an option to be able to disable/enable the editor on the fly so I thought about calling editor.stop() in a function node when I want to disable the editor (and later editor.start() to enable it).

That is not possible to do. You cannot freely start and stop the editor - the API is not designed to support that.

Whether it could be possible is a separate question - but would require some amount of development work to support. It is not a bug as it is not a feature offered by the module.

As for the uncaught exception you've hit - there is something to look at there, but given this path is only hit when Node-RED is shutting down, it isn't too concerning.

---

<div class="post-metadata">

**Author:** ![r0ller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/r0ller/32/14327_2.png) [@r0ller](https://discourse.nodered.org/u/r0ller)\
**Post date:** [4 September 2020 16:06 UTC](https://discourse.nodered.org/t/node-red-crashes-on-calling-editor-stop/32449/5 "2020-09-04T16:06:22Z")

</div>

Okay, understood. The question is then if it's possible in any other way? Afaik, disableEditor cannot be turned on/off on the fly. I also thought about disabling it via http api authorization but currently it's either \* or read and there's no option to block access to the editor only and let http api access open.

Do you happen to have any hint how to get it done?

---

<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:** [4 September 2020 16:10 UTC](https://discourse.nodered.org/t/node-red-crashes-on-calling-editor-stop/32449/6 "2020-09-04T16:10:20Z")

</div>

You could explore adding a custom middleware using `httpAdminMiddleware` in your settings file to block requests however you want, whenever you want.

That would not stop the WebSocket comms link (which is what `editor.start()/stop()` actually controls).

---

<div class="post-metadata">

**Author:** ![r0ller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/r0ller/32/14327_2.png) [@r0ller](https://discourse.nodered.org/u/r0ller)\
**Post date:** [4 September 2020 16:11 UTC](https://discourse.nodered.org/t/node-red-crashes-on-calling-editor-stop/32449/7 "2020-09-04T16:11:00Z")

</div>

Thanks! I'll give it a try 🙂

---

<div class="post-metadata">

**Author:** ![r0ller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/r0ller/32/14327_2.png) [@r0ller](https://discourse.nodered.org/u/r0ller)\
**Post date:** [4 September 2020 20:47 UTC](https://discourse.nodered.org/t/node-red-crashes-on-calling-editor-stop/32449/8 "2020-09-04T20:47:24Z")

</div>

Managed to control it via req.originalUrl but if I'd like to peek in the request body it's just undefined as if there was no bodyparser in place. Is that the case? If so, what can I do about it?

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [5 September 2020 20:06 UTC](https://discourse.nodered.org/t/node-red-crashes-on-calling-editor-stop/32449/9 "2020-09-05T20:06:35Z")

</div>

I have no experience of this myself but maybe you'd be able to add more fine grained control by embedding Node-RED if you're already familiar with Express: [https://nodered.org/docs/user-guide/runtime/embedding](https://nodered.org/docs/user-guide/runtime/embedding)?

---

<div class="post-metadata">

**Author:** ![r0ller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/r0ller/32/14327_2.png) [@r0ller](https://discourse.nodered.org/u/r0ller)\
**Post date:** [30 October 2020 16:20 UTC](https://discourse.nodered.org/t/node-red-crashes-on-calling-editor-stop/32449/10 "2020-10-30T16:20:50Z")

</div>

Hi @knolleary

I know I already asked it but I couldn't solve this since then ☹ Do you happen to have any hint for this?

"Managed to control it via req.originalUrl but if I'd like to peek in the request body it's just undefined as if there was no bodyparser in place. Is that the case? If so, what can I do about it?"

Thanks,  
r0ller

---

<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:** [29 December 2020 16:20 UTC](https://discourse.nodered.org/t/node-red-crashes-on-calling-editor-stop/32449/11 "2020-12-29T16:20:50Z")

</div>

Closed on 29 December 2020 16:20 UTC

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