# Error on stop/restart

**URL:** https://discourse.nodered.org/t/error-on-stop-restart/178
**Category:** General
**Created:** [15 May 2018 12:12 UTC](https://discourse.nodered.org/t/error-on-stop-restart/178 "2018-05-15T12:12:40Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![adam](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@adam](https://discourse.nodered.org/u/adam)
#### Post date: [15 May 2018 12:12 UTC](https://discourse.nodered.org/t/error-on-stop-restart/178/1 "2018-05-15T12:12:40Z")

</div>

I’m getting the following error when stopping or restarting Node-RED:

```
15 May 07:10:00 - [red] Uncaught Exception:
15 May 07:10:00 - Error: write EPIPE
    at _errnoException (util.js:1022:11)
    at WriteWrap.afterWrite [as oncomplete] (net.js:867:14)
nodered.service: Main process exited, code=exited, status=1/FAILURE

```

I don’t know which node is causing the error or where to begin to figure it out. I removed 2 of the custom nodes I was working on from the flows but the error is still present.

---

<div class="post-metadata">

### Author: ![adam](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@adam](https://discourse.nodered.org/u/adam)
#### Post date: [22 May 2018 11:55 UTC](https://discourse.nodered.org/t/error-on-stop-restart/178/2 "2018-05-22T11:55:13Z")

</div>

Bump for help and adding a few characters

---

<div class="post-metadata">

### Author: ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)
#### Post date: [22 May 2018 14:12 UTC](https://discourse.nodered.org/t/error-on-stop-restart/178/3 "2018-05-22T14:12:22Z")

</div>

Best place to start is usually to include the node-red console log output from when the server is started. That shows the versions of nodejs/npm/node-red/dashboard, plus the paths to your flow/static files…

Sounds to me like you have some incompatibility in software versions – so please include a description of the hardware and OS you are using.

---

<div class="post-metadata">

### Author: ![adam](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@adam](https://discourse.nodered.org/u/adam)
#### Post date: [22 May 2018 14:18 UTC](https://discourse.nodered.org/t/error-on-stop-restart/178/4 "2018-05-22T14:18:36Z")

</div>

It’s a Raspberry Pi running Stretch Lite.

Everything is reasonably up to date, but here is the output from the service starting:

```
22 May 09:17:18 - [info] Node-RED version: v0.18.4
22 May 09:17:18 - [info] Node.js version: v8.9.4
22 May 09:17:18 - [info] Linux 4.9.59-v7+ arm LE
22 May 09:17:20 - [info] Loading palette nodes
22 May 09:17:24 - [info] Settings file : /home/pi/.node-red/settings.js
22 May 09:17:24 - [info] HTTP Static : /home/pi/node-red-static
22 May 09:17:24 - [info] User directory : /home/pi/.node-red
22 May 09:17:24 - [info] Server now running at http://127.0.0.1:1880/admin/
22 May 09:17:24 - [info] Active project : timeclock
22 May 09:17:24 - [info] Flows file : /home/pi/.node-red/projects/timeclock/flows_raspberrypi.json
22 May 09:17:25 - [info] Starting flows
22 May 09:17:28 - [info] Started flows
```

---

<div class="post-metadata">

### Author: ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)
#### Post date: [22 May 2018 14:31 UTC](https://discourse.nodered.org/t/error-on-stop-restart/178/5 "2018-05-22T14:31:43Z")

</div>

Yep, that all looks good. So what command(s) are you using to start/stop the service? And if you stop it now that it’s running, do you always get the errors?

It sounds like a problem with the timing of the onClose function and the underlying network library. If this is a custom node, you may need a try/catch block around your cleanup code. I’m not sure if removing the nodes from your flows is enough to stop the errors anyway – you may have to actually npm remove them and restart node-red.

---

<div class="post-metadata">

### Author: ![adam](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@adam](https://discourse.nodered.org/u/adam)
#### Post date: [22 May 2018 14:35 UTC](https://discourse.nodered.org/t/error-on-stop-restart/178/6 "2018-05-22T14:35:13Z")

</div>

I have Node-RED installed as a service so I’m just using `sudo service nodered stop/restart`. The error always appears. I did not think about removing the node with npm, I assumed that if it was not in use it would not be started. I’ll try un-linking the two nodes I made and see if that makes a difference. Once I can figure out what node is even causing the issue I should be able to fix it from there.

---

<div class="post-metadata">

### Author: ![adam](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@adam](https://discourse.nodered.org/u/adam)
#### Post date: [22 May 2018 16:14 UTC](https://discourse.nodered.org/t/error-on-stop-restart/178/7 "2018-05-22T16:14:36Z")

</div>

I updated everything and removed the linked nodes I was working on, but the error is still there (although slightly different now)

```
22 May 10:34:31 - [red] Uncaught Exception:
22 May 10:34:31 - Error: write EPIPE
    at _errnoException (util.js:992:11)
nodered.service: Main process exited, code=exited, status=1/FAILURE

```

After that I got rid of all the nodes I had installed through the palette other than the SQLite node and I am still seeing the error. After updating the SQLite node I now see this error:

```
22 May 11:06:33 - [red] Uncaught Exception:
22 May 11:06:33 - Error: write EPIPE
nodered.service: Main process exited, code=exited, status=1/FAILURE

```

The error message keeps getting smaller and smaller but I’m still not sure what’s causing it. From what I just tried I’m lead to believe it’s associated with the SQLite node, but I still don’t have enough info to troubleshoot it properly.

---

<div class="post-metadata">

### Author: ![adam](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@adam](https://discourse.nodered.org/u/adam)
#### Post date: [22 May 2018 17:09 UTC](https://discourse.nodered.org/t/error-on-stop-restart/178/8 "2018-05-22T17:09:39Z")

</div>

Talking with @dceejay, it seems it may be a SQLite node problem. I’ll post back when I have some more info, but I’m interested to see what others are seeing. With a docker container running on Fedora I do not get this error, but on a Raspberry Pi I do (same version of the SQLite node on both 0.2.2).

---

<div class="post-metadata">

### Author: ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)
#### Post date: [22 May 2018 17:12 UTC](https://discourse.nodered.org/t/error-on-stop-restart/178/9 "2018-05-22T17:12:36Z")

</div>

Interestingly, the npm `sqlite3` module Readme states the following.

> Supported platforms  
> The sqlite3 module works with Node.js v4.x, v5.x, v6.x and v7.x.

So no mention of nodejs v8.9.4, which is what you are using... you could try a manual rebuild of the sqlite3 module, using something like `npm rebuild sqlite3 --force`

---

<div class="post-metadata">

### Author: ![adam](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@adam](https://discourse.nodered.org/u/adam)
#### Post date: [22 May 2018 17:18 UTC](https://discourse.nodered.org/t/error-on-stop-restart/178/10 "2018-05-22T17:18:23Z")

</div>

Doesn’t seem to have done anything, it finished in less than a second (output below). You may be on to something there though, on my docker image I’m using Node.js v6.13.1 but on the Pi I’m using v8.11.2.

```
npm WARN using --force I sure hope you know what you are doing.

> sqlite3@4.0.0 install /home/pi/.node-red/node_modules/sqlite3
> node-pre-gyp install --fallback-to-build

[sqlite3] Success: "/home/pi/.node-red/node_modules/sqlite3/lib/binding/node-v57-linux-arm/node_sqlite3.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile
sqlite3@4.0.0 /home/pi/.node-red/node_modules/sqlite3
```

---

<div class="post-metadata">

### Author: ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)
#### Post date: [12 December 2018 13:25 UTC](https://discourse.nodered.org/t/error-on-stop-restart/178/11 "2018-12-12T13:25:37Z")

</div>

I've the same error on one of my rpi:

```auto
pi@rpi4:~ $ node-red
12 Dec 12:55:41 - [info] 

Welcome to Node-RED
===================

12 Dec 12:55:41 - [info] Node-RED version: v0.19.5
12 Dec 12:55:41 - [info] Node.js version: v8.14.0
12 Dec 12:55:41 - [info] Linux 4.14.79-v7+ arm LE
12 Dec 12:55:42 - [info] Loading palette nodes
12 Dec 12:55:51 - [info] Dashboard version 2.12.2 started at /ui
12 Dec 12:55:52 - [info] Settings file : /home/pi/.node-red/settings.js
12 Dec 12:55:52 - [info] Context store : 'default' [module=localfilesystem]
12 Dec 12:55:52 - [info] Context store : 'memoryOnly' [module=memory]
12 Dec 12:55:52 - [info] User directory : /home/pi/.node-red
12 Dec 12:55:52 - [warn] Projects disabled : set editorTheme.projects.enabled=true to enable
12 Dec 12:55:52 - [info] Flows file : /home/pi/.node-red/flows_rpi4.json
12 Dec 12:55:53 - [info] Server now running at http://127.0.0.1:1880/
12 Dec 12:55:53 - [info] Starting flows
12 Dec 12:55:56 - [info] Started flows
12 Dec 12:55:56 - [info] [mqtt-broker:325f5be5.555734] Connected to broker: mqtt://xxx.xxx.xxx.xxx:1883
^C
12 Dec 12:55:59 - [info] Stopping flows
12 Dec 12:56:00 - [red] Uncaught Exception:
12 Dec 12:56:00 - Error: write EPIPE
    at WriteWrap.afterWrite [as oncomplete] (net.js:868:14)

```

I've found some search results for this error:

```auto
at WriteWrap.afterWrite [as oncomplete] (net.js:868:14)

```

but no usable solutions.

Any ideas where `net.js` is used?

---

<div class="post-metadata">

### Author: ![adam](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@adam](https://discourse.nodered.org/u/adam)
#### Post date: [12 December 2018 13:27 UTC](https://discourse.nodered.org/t/error-on-stop-restart/178/12 "2018-12-12T13:27:22Z")

</div>

Are you using the SQLite node?

---

<div class="post-metadata">

### Author: ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)
#### Post date: [12 December 2018 13:31 UTC](https://discourse.nodered.org/t/error-on-stop-restart/178/13 "2018-12-12T13:31:06Z")

</div>

> [@adam](#):
>
> Are you using the SQLite node?

No, my package.json

```auto
{
  "dependencies": {
    "node-red-admin": "^0.1.3",
    "node-red-contrib-dht-sensor": "~1.0.3",
    "node-red-contrib-ds18b20-sensor": "^1.3.5",
    "node-red-contrib-dsm": "~0.13.2",
    "node-red-contrib-ibm-watson-iot": "~0.2.8",
    "node-red-contrib-ramp-thermostat": "~0.8.0",
    "node-red-contrib-schedex": "~1.4.1",
    "node-red-dashboard": "~2.12.2",
    "node-red-node-dropbox": "~1.0.2",
    "node-red-node-email": "~1.0.7",
    "node-red-node-pushover": "0.0.13",
    "node-red-node-random": "~0.1.2",
    "node-red-node-rbe": "~0.2.4",
    "node-red-node-serialport": "~0.6.3",
    "node-red-node-smooth": "~0.1.0",
    "node-red-node-suncalc": "0.0.11",
    "request": "^2.88.0"
  }
}

```

---

<div class="post-metadata">

### Author: ![adam](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@adam](https://discourse.nodered.org/u/adam)
#### Post date: [12 December 2018 13:59 UTC](https://discourse.nodered.org/t/error-on-stop-restart/178/14 "2018-12-12T13:59:43Z")

</div>

This is mine:

```auto
"dependencies": {
    "alasql": "^0.4.11",
    "full-icu": "^1.2.1",
    "ldapauth-fork": "^4.0.2",
    "moment-timezone": "^0.5.23",
    "node-red-contrib-ibm-watson-iot": "^0.2.8",
    "node-red-contrib-lcd20x4-i2c": "0.0.3",
    "node-red-contrib-mssql-ps": "^1.2.5",
    "node-red-contrib-nr-ldapauth": "~1.0.14",
    "node-red-contrib-play-audio": "^2.3.2",
    "node-red-contrib-pn532": "0.0.2",
    "node-red-node-ping": "0.0.15",
    "node-red-node-random": "^0.1.2",
    "node-red-node-serialport": "^0.6.8",
    "node-red-node-smooth": "^0.1.0",
    "node-red-node-sqlite": "~0.3.5"
  }

```

I'm not actually using node-red-contrib-ibm-watson-iot, node-red-node-random, node-red-node-serialport, or node-red-node-smooth though. I removed all of them and still get the error. My new package.json:

```auto
"dependencies": {
    "alasql": "^0.4.11",
    "full-icu": "^1.2.1",
    "ldapauth-fork": "^4.0.2",
    "moment-timezone": "^0.5.23",
    "node-red-contrib-lcd20x4-i2c": "0.0.3",
    "node-red-contrib-mssql-ps": "^1.2.5",
    "node-red-contrib-nr-ldapauth": "~1.0.14",
    "node-red-contrib-play-audio": "^2.3.2",
    "node-red-contrib-pn532": "0.0.2",
    "node-red-node-ping": "0.0.15",
    "node-red-node-sqlite": "~0.3.5"
  }

```

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [12 December 2018 14:29 UTC](https://discourse.nodered.org/t/error-on-stop-restart/178/15 "2018-12-12T14:29:23Z")

</div>

@cflurin - Did you do a startup and an immediate ctrl-c to stop NR?  
What are the flows doing?  
Any HTTP nodes being used?

---

<div class="post-metadata">

### Author: ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)
#### Post date: [12 December 2018 14:42 UTC](https://discourse.nodered.org/t/error-on-stop-restart/178/16 "2018-12-12T14:42:12Z")

</div>

> [@zenofmud](#):
>
> Did you do a startup and an immediate ctrl-c to stop NR?  
> What are the flows doing?  
> Any HTTP nodes being used?

1. No, I just started `node-red` in the terminal and used `<ctrl-c>` to log the error in the terminal.  
It happens also after hours.

2. Running several flows

3. `http request` node

---

<div class="post-metadata">

### Author: ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)
#### Post date: [12 December 2018 14:44 UTC](https://discourse.nodered.org/t/error-on-stop-restart/178/17 "2018-12-12T14:44:55Z")

</div>

So far I've found `net.js` is used by node.js.

```auto
function afterWrite(status, handle, req, err) {
  var self = handle.owner;
  if (self !== process.stderr && self !== process.stdout)
    debug('afterWrite', status);

  // callback may come after call to destroy.
  if (self.destroyed) {
    debug('afterWrite destroyed');
    return;
  }

  if (status < 0) {
[line 668] var ex = errnoException(status, 'write', req.error);
    debug('write failure', ex);
    self.destroy(ex, req.cb);
    return;
  }

```

---

<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: [12 December 2018 21:59 UTC](https://discourse.nodered.org/t/error-on-stop-restart/178/18 "2018-12-12T21:59:43Z")

</div>

Does it happen if you use the normal way to start and stop node-red which is `node-red-start` and `node-red-stop`?  
I wonder whether this is related to the problem with node context not being saved on stopping node-red.

> [@Persistent data not being saved](https://discourse.nodered.org/t/persistent-data-not-being-saved/5680/13):
>
> I just verified this (in OSX) in terminal, start NR create a simple flow (attached below) - an inject to two change nodes - each change node to a seperate debug node set one change node to use a flow variable the other uses a global variable. deploy and press the inject and use the 'context data' to examine the contents. as soon as you see the timestamp in the context data, press the inject again and then swap to the terminal and press CTRL-C If you go edit .node-red/context/global/flobal.jso…

---

<div class="post-metadata">

### Author: ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)
#### Post date: [13 December 2018 08:23 UTC](https://discourse.nodered.org/t/error-on-stop-restart/178/19 "2018-12-13T08:23:43Z")

</div>

> [@Colin](#):
>
> Does it happen if you use the normal way to start and stop node-red which is `node-red-start` and `node-red-stop` ?

Yes, it does.

You can run/stop node-red using `node-red-start` and `node-red-stop` in one terminal.  
Open a second terminal and run

```auto
sudo journalctl -n 50 -f -u nodered -o cat

```

to display the log.  
Probably there are more users facing this error, but they don't see it when stopping node-red.
