1

(When I run same code on ubuntu with node 4.2.6. I don't see this problem. )
I found some has similar problem: Express.js close response

==============problem description=========================
I encountered a very strange problem. In my Express project, I am using passport package. As long as I signed in myself, then every page will keep loading for 2 minutes. If I am not logged in, I found pages behave normally.

/* GET home page. */
router.get('/', function (req, res, next) {
    res.render('index', {
        title: 'FASIDS',
        activePage:'Home',
        isAuthenticated: req.isAuthenticated(),
        user: processReqUser(req.user)
    }, function (err, html) {
        if (err) {
            next(err);
            return;
        }
        res.send(html);
    });
});

I have to substitute res.send(html) with res.end(html) to make my code behaves normally in both situations ("signed in" or "not signed in").

Really have no idea how to deal with it. Please help.

Additionally, please refer my processedPassport.js to see how I am handling authentication.

The passport is used in app.js as following:

...irrelevant code..

var passport = require('./components/processedPassport.js').addPassport(app, db_models);

...irrelevant code....

For reference, I included screenshots
Following pic shows a loading time of 2 mins screenshots showing 2 min long loading time

Following pic shows request and response headers response header

Community
  • 1
  • 1
Bowei Liu
  • 161
  • 1
  • 9
  • Can you post how you handle authentication in passport.js itself? It seems your code is doing everything correctly in the route handling. – ngoctranfire Mar 28 '16 at 18:15
  • @ngoctranfire please refer https://github.com/bovetliu/FASIDS_proto/blob/master/components/processedPassport.js to see my authentication code. – Bowei Liu Mar 28 '16 at 18:18
  • If `res.end()` works, what exactly is the problem? `res.end()` both sends a response and ends the request object, which should be good behaviour (unless you want a persistent connection?). – Akshat Mahajan Apr 01 '16 at 15:21
  • @AkshatMahajan The only difference I observed is that, res.end() will include Transfer-Encoding:chunked after I logged in. Using res.send() will not include this header field, instead, I will find"Date:Sat, 02 Apr 2016 15:22:56 GMT ETag:W/"9b-jJAq3AISRHi+ZUZBsrt/Mw" in response header – Bowei Liu Apr 02 '16 at 15:23

0 Answers0