# Saving dual line graph state to file gives write error, still works

**URL:** https://discourse.nodered.org/t/saving-dual-line-graph-state-to-file-gives-write-error-still-works/3514
**Category:** Dashboard
**Created:** [27 September 2018 19:50 UTC](https://discourse.nodered.org/t/saving-dual-line-graph-state-to-file-gives-write-error-still-works/3514 "2018-09-27T19:50:53Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![OverWorldD](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/overworldd/32/2844_2.png) [@OverWorldD](https://discourse.nodered.org/u/OverWorldD)
#### Post date: [27 September 2018 19:50 UTC](https://discourse.nodered.org/t/saving-dual-line-graph-state-to-file-gives-write-error-still-works/3514/1 "2018-09-27T19:50:53Z")

</div>

Hi! First time poster, hope I'm making sense...

I have got a flow that uses the graph node with two different msg.topics at the input to graph two lines. I also have single graphs. All graph states are saved in textfiles and re-pushed into the graphs at startup. The single line graphs that are set up the same way, except they only receive one msg (not two topics), save without error - However. The graphs that have two lines in them give the following write error when writing the textfile on the chart state output.

"failed to write to file: Error [ERR\_STREAM\_WRITE\_AFTER\_END]: write after end"

It seems like the dual topics cause the node to do try writing a second time without opening the file correctly or something like that. I'm not a programmer so that's why I have to ask here if it's a bug or if it is somehting I'm doing wrong.

Strangely enough it seems to save the data correctly into the file even with this error(?)

To re-create:  
connect the chart state output to a textfile and feed the graph with two streams with different topics

 ![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/b9838233988615d6d5804c7f7004f96254968d0b.png)

---

<div class="post-metadata">

### Author: ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)
#### Post date: [27 September 2018 20:34 UTC](https://discourse.nodered.org/t/saving-dual-line-graph-state-to-file-gives-write-error-still-works/3514/2 "2018-09-27T20:34:35Z")

</div>

Seems to be bug indeed. Data is written to file but errors with every injection in debug window.

Flow

```auto
[{"id":"27abf46f.5e2dec","type":"inject","z":"e4fbed1c.b901f","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":310,"y":320,"wires":[["89d4758.401dc88"]]},{"id":"89d4758.401dc88","type":"function","z":"e4fbed1c.b901f","name":"generate","func":"var a = Math.floor(Math.random()*9)\nvar b = Math.floor(Math.random()*9)\nvar aa = {payload:a,topic:\"A\"}\nvar bb = {payload:b,topic:\"B\"}\nreturn [aa,bb];\n//return [[aa,bb]];","outputs":2,"noerr":0,"x":470,"y":320,"wires":[["8643ebac.c26988"],["8643ebac.c26988"]]},{"id":"8643ebac.c26988","type":"ui_chart","z":"e4fbed1c.b901f","name":"","group":"e76429b2.ef5418","order":0,"width":0,"height":0,"label":"chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"20","removeOlderPoints":"300","removeOlderUnit":"1","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":640,"y":320,"wires":[["6cbccf6.f3ad43"],[]]},{"id":"6cbccf6.f3ad43","type":"file","z":"e4fbed1c.b901f","name":"","filename":"D:\\temp\\chart.txt","appendNewline":false,"createDir":false,"overwriteFile":"true","x":800,"y":300,"wires":[[]]},{"id":"c21bb33d.db0ea","type":"inject","z":"e4fbed1c.b901f","name":"clear","topic":"","payload":"[]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":450,"y":270,"wires":[["8643ebac.c26988"]]},{"id":"e76429b2.ef5418","type":"ui_group","z":"","name":"Default","tab":"d9bdf874.ea4088","disp":true,"width":"6","collapse":false},{"id":"d9bdf874.ea4088","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]

```

By increasing the count of topics (add more chart lines), errors will increase accordingly. 4 lines will create 3 errors.

`27 Sep 23:51:57 - [error] [file:b131d817.707898] failed to write to file: Error: write after end`

---

<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: [27 September 2018 21:22 UTC](https://discourse.nodered.org/t/saving-dual-line-graph-state-to-file-gives-write-error-still-works/3514/3 "2018-09-27T21:22:08Z")

</div>

same as [File Node signal error by overwrite file](https://discourse.nodered.org/t/file-node-signal-error-by-overwrite-file/3495/5)

---

<div class="post-metadata">

### Author: ![OverWorldD](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/overworldd/32/2844_2.png) [@OverWorldD](https://discourse.nodered.org/u/OverWorldD)
#### Post date: [27 September 2018 22:59 UTC](https://discourse.nodered.org/t/saving-dual-line-graph-state-to-file-gives-write-error-still-works/3514/4 "2018-09-27T22:59:09Z")

</div>

Ok, it's not me then. Good 😉 Thanx, guys. Is there somewhere this bug should be reported besides here?

---

<div class="post-metadata">

### Author: ![OverWorldD](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/overworldd/32/2844_2.png) [@OverWorldD](https://discourse.nodered.org/u/OverWorldD)
#### Post date: [27 September 2018 23:17 UTC](https://discourse.nodered.org/t/saving-dual-line-graph-state-to-file-gives-write-error-still-works/3514/5 "2018-09-27T23:17:36Z")

</div>

Great, I saw the workaround so I added "1 msg per 3 sec limit" nodes between the output and the filewriter. Seems to have got rid of the errors.

Maybe there should be a limit in the graph node itself.

Thanx again.

---

<div class="post-metadata">

### Author: ![Bambulko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bambulko/32/3126_2.png) [@Bambulko](https://discourse.nodered.org/u/Bambulko)
#### Post date: [14 October 2018 10:27 UTC](https://discourse.nodered.org/t/saving-dual-line-graph-state-to-file-gives-write-error-still-works/3514/6 "2018-10-14T10:27:43Z")

</div>

how did you do it?

---

<div class="post-metadata">

### Author: ![cthierman](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cthierman/32/57627_2.png) [@cthierman](https://discourse.nodered.org/u/cthierman)
#### Post date: [29 October 2018 03:08 UTC](https://discourse.nodered.org/t/saving-dual-line-graph-state-to-file-gives-write-error-still-works/3514/7 "2018-10-29T03:08:03Z")

</div>

I'm wondering if this got reported as a BUG, I too am seeing that problem. Did you just put a delay node between your graph and the file write, is that how you worked around it for now?

---

<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: [29 October 2018 08:55 UTC](https://discourse.nodered.org/t/saving-dual-line-graph-state-to-file-gives-write-error-still-works/3514/8 "2018-10-29T08:55:38Z")

</div>

> [@cthierman](#):
>
> I'm wondering if this got reported as a BUG

If you follow @zenofmud's link a few posts ago you will see that it already been fixed in the development code, so I assume this will be included in the next release of node red.
