Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Cannot set headers after they are sent to the client #496

Open
ChasLui opened this issue May 27, 2018 · 10 comments
Open

Cannot set headers after they are sent to the client #496

ChasLui opened this issue May 27, 2018 · 10 comments

Comments

@ChasLui
Copy link

ChasLui commented May 27, 2018

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)
@Panjks
Copy link

Panjks commented Jun 4, 2018

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

@FlanBr-yopG
Copy link

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

@damianstasik
Copy link

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

@Cetheus
Copy link

Cetheus commented Jun 14, 2018

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.

@hworost
Copy link

hworost commented Jun 27, 2018

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

@LeonardoCurvelo
Copy link

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

@jsEveryDay
Copy link

@LeonardoCurvelo works perfect now :)

@DanielDiBe
Copy link
Contributor

DanielDiBe commented Jul 27, 2018

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.

nightwing pushed a commit that referenced this issue Aug 9, 2018
nightwing added a commit that referenced this issue Aug 9, 2018
Fix issue #496: Cannot set headers after they are sent to the client
@azeez-abp
Copy link

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

@faienz93
Copy link

faienz93 commented Sep 9, 2019

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests