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

#1

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

#2

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

Flow

[{"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

#3

same as File Node signal error by overwrite file

#4

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

#5

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.

#6

how did you do it?

#7

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?

#8

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.