Repository: node-opcua/node-opcua

Issue #607: Crash when using node-opcua server inside electron on Mac and Linux
Created: 2019-03-07T09:15:22Z
I'm submitting a ...  (check one with "x")

(x) bug report => search github for a similar issue or PR before submitting
( ) feature request
( ) support request => Please do not submit support request here, instead see use

use gitter or stackoverflow for community support, or
contact Sterfive for commercial support



Current behavior

When importing opcua-server in an electron app.
import { startOpcuaServer } from './opcua/opcua-server';

It causes the program to never end importing dependencies and go into an endless loop of starting new electron applications till memory runs out.
Expected behavior

App continues with main routine after importing and display the UI. This is for the UI of an industrial control application which is running on equipment on the shopfloor.
Minimal reproduction of the problem with instructions


create a minimal electron app. e.g. https://github.com/electron-react-boilerplate/electron-react-boilerplate
add a dependency on opcua : yarn add node-opcua
and an import : import { startOpcuaServer } from './opcua/opcua-server';
package the app for linux : yarn package-linux
install the package: sudo dpkg -i release/electron-react-boilerplate_0.17.1_amd64.deb
run the app : /opt/ElectronReact/electron-react-boilerplate
observe that the app is hanging and no output is generated.
open another terminal and run top and observe the electron processes breed like rabbits.

What happens is that the fqdn module used by node-opcua-hostname package depends on an old version of shelljs. Shelljs uses process.execPath to find the name of the node executable to run small dynamically generated javascript scripts to run system commands. In most cases the node executably is the top level process and this works fine. For electron apps, this actually points to electron app which wraps node and starts a browser and the 2 javascript enviroments for the frontend and backend.
When the fqdn library is used during imports it, it tries to call hostname by this method by executing the script with call to the program pointed to by process.execPath mistakensy assuming it points to the node interpreter. This keeps starting the electron app and initializing the app till memory runs out.
The fqdn library and shelljs libraries are only used from node-opcua-hostname package, and can be relatively easy be replaced with os.hostname() plus a dns lookup on Mac and Linux.
Windows is not affected, as this calling of hostname only happens on unix platforms as for windows it is derived differently.
What is the motivation / use case for changing the behavior?

Blocks deployment of OPC/UA to the shopfloor for our company.
Please tell us about your environment:



( ) my request is related to node-opcua acting as a  OPCUA CLIENT


(x)  my request is related to node-opcua acting as a OPCUA SERVER


( ) I have installed node-opcua from source ( using git clone)


(x) I have installed node-opcua as a package ( using npm install )


( ) I am using an application that uses node-opcua

( ) node-red
( ) other : please specify



Device: Xpeqt XTD Automatic Test Equipment


OS version: Ubuntu 14-04 and 18.04

( ) Windows : version : _________
(x) Linux   : version : Ubuntu 18.04
(x) MacOs   : version : Sierra
(?) Raspbian: version : _________
( ) Other   : specify :



Description of the other OPCUA system I am trying to connect to:

Name: see above, it is a server
Version:_________
Manufacturer/Software vendor:_________
link : https://



node-opcua version:  : "0.5.8"





Node:
node --version = v10.15.2  but probably not relevant

it happens with various electron versiong going back to 2.0.x

Duplicate issue #602: Don't work node-opcua >= 0.5.0  to nwjs > 0.33.4 (node 11.0.0)
Created: 2019-03-01T09:20:14Z
How to title of this post, why?
The project don't works for version 0.5.0, but is the nodejs version of the problem?

Device: Desktop
OS version: MacOS 10.13.6

Closing comment (2019-03-17T14:48:27Z): Thank you @fbalazsy , Let's close and label this issue as a duplicate of #607