No Request Status in Node.js Morgan Logging

2019-07-19 04:53发布

I'm running a node.js app on an Azure VM (with PM2 handling load balancing and restarting). Here's the server set up and logging code:

var logger = require('morgan');
var app = express();

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(flash());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', routes);
app.use('/api/v01', api.router);
app.use('/api/v02', apiv2.router);

In the last day or so, we've started to have a lot of trouble connecting to the website. It takes a few reloads to get any data to show up.

I've been looking through the logs trying to figure out what is up. I don't see any errors, but there are quite a few instances of this sort of thing:

WebApp-2 GET /portal - - ms - -
WebApp-3 GET /portal - - ms - -
WebApp-2 GET / - - ms - -
WebApp-2 GET / - - ms - -

These seem to coincide with people being unable to view the pages. When things are working, the logs look more like this:

WebApp-3 GET / 302 16.532 ms - 58
WebApp-3 GET /portal 200 335.192 ms - 5239

The format is :method :url :status :response-time ms - :res[content-length] according to the Morgan docs.

One thing I've noticed is that when the server isn't really working, the logging has the - character in place of the status, response time, and content length. I'm used to seeing - for content-length; it's what happens when the server responds with a 304. I've never seen the - for response time or status though, Despite searching (both Google and here on SO) I'm unclear what this really means (under the hood).

Does anyone know what this lack of status means? If it has a well understood meaning, is there a mistake that I'm making that would lead to this?

3条回答
Emotional °昔
2楼-- · 2019-07-19 05:28

On windows, for node.js I found similar issue, and the reason was blocking firewall. After allowing node, and node.js apps through both private and public, it resolved.

查看更多
别忘想泡老子
3楼-- · 2019-07-19 05:31

I would try to explain the probable cause in simple terms as I too came across the same problem sometime back. The issue was that for a certain condition in code, the line "res.send" wasn't getting executed. Therefore, the response that is being awaited on the client side was getting timed out. And hence, in the logger, it showed /GET docs - - ms - - as we didn't send anything in response.

查看更多
\"骚年 ilove
4楼-- · 2019-07-19 05:43

According to the issue report here, GET / - - ms - - essentially means that "you never sent a response before Node.js killed the TCP connection for idling too long".

Check to make sure that each request is sent a response.

查看更多
登录 后发表回答