cmseaton42 / node-ethernet-ip

A Lightweight Ethernet/IP API written to interface with Rockwell ControlLogix/CompactLogix Controllers.
MIT License
265 stars 106 forks source link

Process crash when using destroy methods #63

Open aurelhann opened 4 years ago

aurelhann commented 4 years ago

Current Behavior

On a specific devices or/and particular network failures , use the destroy method to ends the devices connection will end all the process

10 Jan 11:09:35 - Error: This socket has been ended by the other party
    at Controller.writeAfterFIN [as write] (net.js:407:14)
    at Controller.destroy (/home/aurelien/repos/braincubeiot2-contrib-ethernetip/.bin/red/ethernetip.js:1118:14)
    at destroyPLC (/home/aurelien/repos/braincubeiot2-contrib-ethernetip/.bin/red/ethernetip.js:8162:31)

Expected Behavior

Normally when a socket is gone don't try to write something on it.

Possible Solution (Optional)

Apply this changement in your destroy method like that

destroy(exception) {
        const { unregisterSession } = encapsulation;
        if(this.destroyed) return ;
        this.write(unregisterSession(this.state.session.id), () => {
            this.state.session.established = false;
            super.destroy();
        });
    }

Context

My connection pass through a proxy and fucked up some times. And close connections.

Steps to Reproduce (for bugs only)

  1. Make a connection to your plc
  2. Disconnect it mecanicly
  3. Apply the destroy method
  4. See whats happened !

Your Environment