Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest master (newer than 2.2.16) throws exception #2389

Closed
smassin opened this issue Jul 25, 2016 · 4 comments
Closed

Latest master (newer than 2.2.16) throws exception #2389

smassin opened this issue Jul 25, 2016 · 4 comments

Comments

@smassin
Copy link

smassin commented Jul 25, 2016

Issue Description

The latest master or newer than 2.2.16 is throwing an exception and crashing whenever making a query.

Whenever a query is made the following error occurs in the logs:

Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:344:11)
at expressInit (.../node_modules/express/lib/middleware/init.js:23:42)
at Layer.handle as handle_request
at trim_prefix (.../node_modules/express/lib/router/index.js:312:13)
at .../node_modules/express/lib/router/index.js:280:7
at Function.process_params (.../node_modules/express/lib/router/index.js:330:12)
at next (.../node_modules/express/lib/router/index.js:271:10)
at query (.../node_modules/express/lib/middleware/query.js:49:5)
at Layer.handle as handle_request
at trim_prefix (.../node_modules/express/lib/router/index.js:312:13)

I couldn't find anything on ParseServer.js:431 that seemed related though.
Using [email protected] works just fine.

Steps to reproduce

Please include a detailed list of steps that reproduce the issue. Include curl commands when applicable.

  1. Install the latest parse-server (npm install parse-server)
  2. Launch the server. (I'm using forever to run it with node)
  3. Make any cloud request with a query.

Expected Results

No error.

Actual Outcome

Server throws exception:
Error: Can't set headers after they are sent.

Environment Setup

  • Server
    • parse-server version: 2.2.17 ?
    • Operating System: Ubuntu
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): Azure
  • Database
    • MongoDB version: N/A
    • Storage engine: N/A
    • Hardware: N/A
    • Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): Azure

Logs/Trace

Oddly enough VERBOSE made the error message go away but the problem still exists.

However, from my own logs I can tell this is happening every time a query is made.

@tillifywebb
Copy link

Yes we have same error, we have rolled back as it was crashing our app

#2338

@j-koenig
Copy link

Same here...

@johnnydimas
Copy link
Contributor

johnnydimas commented Jul 28, 2016

I had the same issue after I updated as well.

I am using express to catch any errors, so what I did was check if the response headers had already been sent to the client before handling my errors.

This seems to take care of it for me for now so I can continue with the latest parse, but not sure if there is a fix or better solution to this out there.

// catch 404 and forward to error handler
app.use(function(req, res, next) {
    // Fixes issue with cloud code
    if (res.headersSent) {
        return next(err);
    }
    var err = new Error('Not Found');
    err.status = 404;
    next(err);
});

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
   // Fixes issue with cloud code
   if (!res.headersSent) {
        res.status(err.status || 500);
        res.render('error', {
            message: err.message,
            error: {}
        });
    }
});

There is some documentation for this also on the express site at the bottom under the heading "The Default Error Handler".

http://expressjs.com/en/guide/error-handling.html

@flovilmart
Copy link
Contributor

Closing as duplicate of #2362

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

No branches or pull requests

5 participants