c9 / core

Cloud9 Core - Part of the Cloud9 SDK for Plugin Development https://c9.github.io/core/ https://c9.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot set headers after they are sent to the client

ChasLui opened this issue · comments

i use nginx proxy 80 port to localhost:8181 , nginx.conf

   server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
             proxy_pass http://localhost:8181;
             proxy_set_header Host $host;
             proxy_set_header X-Real-IP $remote_addr;
             proxy_redirect default;
             proxy_http_version 1.1;
             proxy_set_header Upgrade $http_upgrade;
             proxy_set_header Connection 'upgrade';
        }

    }

error

[root@VM_21_58_centos c9sdk]# node server.js 
Starting standalone
Connect server listening at http://127.0.0.1:8181
CDN: version standalone initialized /root/c9sdk/build
Started '/root/c9sdk/configs/standalone' with config 'standalone'!
Cloud9 is up and running
cache /root/c9sdk/build/standalone/skin/default/dark.css
cache hit /root/c9sdk/build/standalone/skin/default/dark.css
_http_outgoing.js:471
    throw new ERR_HTTP_HEADERS_SENT('set');
    ^

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (_http_outgoing.js:471:11)
    at ServerResponse.res.setHeader (/root/c9sdk/node_modules/connect/lib/patch.js:63:22)
    at ServerResponse.<anonymous> (/root/c9sdk/node_modules/connect/lib/patch.js:81:14)
    at Array.forEach (<anonymous>)
    at ServerResponse.res.writeHead (/root/c9sdk/node_modules/connect/lib/patch.js:80:28)
    at ServerResponse.res.json (/root/c9sdk/node_modules/frontdoor/lib/middleware.js:23:17)
    at IncomingMessage.<anonymous> (/root/c9sdk/plugins/c9.vfs.server/vfs.server.js:141:21)
    at IncomingMessage.emit (events.js:182:13)
    at resOnFinish (_http_server.js:564:7)
    at ServerResponse.emit (events.js:182:13)

I had the same problem. But I didn't use the proxy. The same error when I tried to initialize the ide.

I fixed it by use node v7.5 except node v10

Node v8 also works. I have also seen c9 core running on node v9 and v10 fail with this error.

The latest working version is v10.1.0, everything newer than this fails with error @ChasLui mentioned.

I am running into this Error on every Node Version by now.
I tried 7.5.0, 8.0.0, 10.1.0 and the latest Stable 10.4.1

Did I miss something?

ok... Got my Error...
The Node Version was not applied correctly. I removed my node Installation and reinstalled 10.1.0.
Now its Working.

Yeap, was there...
Came back to 10.1.0:
sudo n 10.1.0
and then
git reset --hard
in the c9sdk folder.

I encountered this problem.

For many reasons I couldn't change the nodejs version, but I "fixed" the problem by commenting out line 141 on plugins/c9.vfs.server/vfs.server.js
I really don't know what side effects that will cause, but now I can be productive again.

Just thought I'd share my experience

@LeonardoCurvelo works perfect now :)

Better than commenting out the line, just modify it to check if headers have been already sent before sending a new response to the client:

if(!res.headersSent) res.json({}, 0, 500);

Node.js headersSent reference.

I think the best way is to set a variable outside the block of your code and assign it to what ever to be sent out and finally outside the block send out only one output, passing the variable as what to send out

Better than commenting out the line, just modify it to check if headers have been already sent before sending a new response to the client:

if(!res.headersSent) res.json({}, 0, 500);

Node.js headersSent reference.

Yes, I have Node js v11.9.0 with Express.js Server 4.16.4 and this resolve the problem