Node-red crashes on calling editor.stop()

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

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?

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().

Okay... lets take a step back.

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.

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?

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).

Thanks! I'll give it a try :slight_smile:

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?

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?

Hi @knolleary

I know I already asked it but I couldn't solve this since then :frowning: 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

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