[http input -> tcp request -> http response] Error: Can't set headers after they are sent.

723 views
Skip to first unread message

Eddy Yanto

unread,
Dec 22, 2015, 10:54:50 PM12/22/15
to Node-RED
Hi,

I have a video device at 192.168.1.98:7000 and I would like to see its status from a web browser whenever I go to Node-RED-url/power. I configured my flow as below:

[{"id":"a7cf0f49.5830f","type":"function","z":"3891fcbe.c76e04","name":"parse result","func":"msg.payload = msg.payload.toString(\"utf8\");\nmsg.status = 200;\nreturn msg;","outputs":"1","noerr":0,"x":783,"y":235,"wires":[["bbdf883f.442078","538dc48b.ac723c"]]}]


If I run Node-RED for the first time and open http://192.168.1.10:1880/power in a browser, I am able to get the status response from my video device. But if I try to refresh the browser subsequently, the browser just stayed there waiting for a response and some error messages showed up on the debug tab:

12/23/2015, 11:38:29 AMbbdf883f.442078
msg
: error
Error: Can't set headers after they are sent.

What should I change to make it work without restarting Node-RED? I guess I probably did it the wrong way, any pointer is appreciated!

Dave C-J

unread,
Dec 23, 2015, 6:32:12 AM12/23/15
to node...@googlegroups.com
Hi

You are fine...
I think you have found a bug we fixed a week or so ago...
The TCPget node doesn't pass through the existing message properties so the http response node never gets the expected properties that it needs to finish the previous request.
The fix is now in the 0.12.4 release.

Eddy Yanto

unread,
Dec 23, 2015, 9:00:04 AM12/23/15
to Node-RED
Strange, I was using Node-RED 0.12.4 when I saw that error message. Here's my flow again in its entirety:

[{"id":"4b69de06.b4962","type":"tcp request","z":"3891fcbe.c76e04","server":"192.168.1.98","port":"7000","out":"time","splitc":"1000","name":"Video Device","x":493,"y":183,"wires":[["2cd6f9c5.d32906"]]},{"id":"a148b791.5eb748","type":"http in","z":"3891fcbe.c76e04","name":"","url":"/power","method":"get","swaggerDoc":"","x":102,"y":183,"wires":[["3923f36a.c6dc0c"]]},{"id":"3923f36a.c6dc0c","type":"function","z":"3891fcbe.c76e04","name":"Power Command","func":"msg.payload = \"*power = ?<CR>\\r\\n\";\nreturn msg;","outputs":1,"noerr":0,"x":294,"y":183,"wires":[["4b69de06.b4962"]]},{"id":"2cd6f9c5.d32906","type":"function","z":"3891fcbe.c76e04","name":"Parse Result","func":"msg.payload = msg.payload.toString('utf8');\nreturn msg;","outputs":1,"noerr":0,"x":681,"y":183,"wires":[["dcb3bf0b.234c4","d33f1868.2cc0e8"]]},{"id":"dcb3bf0b.234c4","type":"http response","z":"3891fcbe.c76e04","name":"","x":886,"y":238,"wires":[]},{"id":"d33f1868.2cc0e8","type":"debug","z":"3891fcbe.c76e04","name":"","active":true,"console":"false","complete":"false","x":902,"y":122,"wires":[]}]

First request was okay but subsequent calls were always broken, here's the Node-RED console log:

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

23 Dec 21:54:26 - [info] Node-RED version: v0.12.4
23 Dec 21:54:26 - [info] Node.js  version: v4.2.3
23 Dec 21:54:26 - [info] Loading palette nodes
23 Dec 21:54:28 - [warn] ------------------------------------------
23 Dec 21:54:28 - [warn] [rpi-gpio] Info : Ignoring Raspberry Pi specific node
23 Dec 21:54:28 - [warn] [tail] Not currently supported on Windows.
23 Dec 21:54:28 - [warn] ------------------------------------------
23 Dec 21:54:28 - [info] Settings file  : C:\Users\HP\AppData\Roaming\npm\node_modules\node-red\settings.js
23 Dec 21:54:28 - [info] User directory : C:\Users\HP\.node-red
23 Dec 21:54:28 - [info] Flows file : C:\Users\HP\.node-red\flows_HP-PC.json
23 Dec 21:54:28 - [info] Server now running at http://127.0.0.1:1880/
23 Dec 21:54:28 - [info] Starting flows
23 Dec 21:54:28 - [info] Started flows
23 Dec 21:54:37 - [info] Stopping flows
23 Dec 21:54:37 - [info] Stopped flows
23 Dec 21:54:37 - [info] Starting flows
23 Dec 21:54:37 - [info] Started flows
23 Dec 21:55:14 - [error] [http response:dcb3bf0b.234c4] Error: Can't set headers after they are sent.
23 Dec 21:57:00 - [error] [http response:dcb3bf0b.234c4] Error: Can't set headers after they are sent.

Any idea?

Dave C-J

unread,
Dec 23, 2015, 11:59:29 AM12/23/15
to node...@googlegroups.com
Aha - yes... working on a fix

Dave C-J

unread,
Dec 23, 2015, 3:02:54 PM12/23/15
to node...@googlegroups.com

Eddy Yanto

unread,
Dec 23, 2015, 8:25:32 PM12/23/15
to Node-RED
Thanks Dave, you're fast! I applied your fix and I confirm that it is working on my system.
Reply all
Reply to author
Forward
0 new messages