我的节点服务器正常运行。绝对没有问题。 然后在某个(随机?)时间点,它停止响应请求。 (之前它确实不间断地响应了几个小时。)
没有错误。服务器仍然可以执行内部进程,但不响应请求。
这样,当日志显示时,请求正在进入服务器:
GET / - - ms - -
GET / - - ms - -
GET /upload - - ms - -
GET /profile - - ms - -
我无法弄清楚它什么时候被触发,发生了什么,以及它为什么会发生。
一旦服务器停止响应,它将永远不会再响应。重新启动服务器可以解决问题,直到再次发生。
有人遇到过这种行为吗?
更新:
同样,服务器永远不会崩溃,只是停止响应。
这些是我用于服务器的组件:
var express = require('express');
var app = express();
var port = process.env.PORT || 8080;
var morgan = require('morgan');
var cookieParse = require('cookie-parser');
var session = require('express-session');
var mongoose = require ('mongoose');
var bodyParser = require('body-parser');
var configDB = require('./config/database');
var passport = require('passport');
var flash = require('connect-flash');
var MongoStore = require('connect-mongo')(session);
var https = require("https");
var path = require('path');
var helmet = require ("helmet");
var robots = require("express-robots");
var Sitemap = require('sitemap')
var async = require('async')
var cron = require('node-schedule');
var compression = require('compression')
更新
添加了带注释的pm2日志:
0|server | GET /public/js/fullscreen.js 304 72.626 ms - -
0|server | GET /public/js/mathUtils.js 304 72.291 ms - -
0|server | GET /public/js/snap.svg.js 304 74.047 ms - -
0|server | GET /views/58dc059bf5ac4394447e7a4d/82z7rw8qbvgqfr 304 95.918 ms - -
0|server | GET /public/js/playerTransport.js 304 96.425 ms - -
0|server | GET /public/res/img/rightarrow.png 304 82.923 ms - -
0|server | GET /public/res/img/BecomicsLogo.png 304 93.323 ms - -
0|server | GET /public/res/img/leftarrow.png 304 84.158 ms - -
0|server | GET /public/res/img/fullscreen.png 304 93.776 ms - -
0|server | GET /public/fonts/foundation-icons.woff 304 61.611 ms - -
0|server | GET /public/images/ui-bg_glass_100_f6f6f6_1x400.png 404 57.253 ms - 39
0|server | GET /public/images/ui-icons_ef8c08_256x240.png 404 57.646 ms - 39
0|server | POST /rating/get 200 111.758 ms - 37
0|server | POST /player/getBook?id=58dc059bf5ac4394447e7a4d 200 99.961 ms - -
0|server | GET /public/res/img/loading.gif 304 70.614 ms - -
0|server | POST /stats/pageView 200 73.545 ms - 2
0|server | GET /subscriptions 304 655.215 ms - -
0|server | GET /public/css/discover.css 304 72.171 ms - -
0|server | GET /public/css/becomics.css 304 73.344 ms - -
0|server | GET /public/js/spf.js 304 65.621 ms - -
0|server | GET /public/res/img/hamburgerMenu.png 304 58.525 ms - -
0|server | POST /subscriptions/count 200 111.033 ms - 11 <--- This is the last time the server will respond
0|server | GET /profile/5825063e47234fc77cbc7694/$otherUserPic - - ms - -
0|server | GET /profile/5825063e47234fc77cbc7694/$picTheWhat - - ms - -
0|server | So far so good <--This prints just before the res.send(). It verifies that the request makes it all the way to the response. But still. No response...
0|server | So far so good
0|server | GET /profile/5825063e47234fc77cbc7694/$otherUserPic - - ms - -
0|server | GET /profile/5825063e47234fc77cbc7694/$picTheWhat - - ms - -
0|server | GET /subscriptions - - ms - -
0|server | GET /profile/5825063e47234fc77cbc7694 - - ms - -
0|server | GET /profile/5825063e47234fc77cbc7694 - - ms - -
0|server | Counting Views. <--- this is a croned operation. It executes with no problem. Even after server stopped responding.
0|server | GET /profile/5825063e47234fc77cbc7694 - - ms - -
0|server | GET / - - ms - -
0|server | GET /profile/5806a8116b9b49b4201f5487 - - ms - -
0|server | GET /trendy?spf=navigate - - ms - -
0|server | GET /trendy?spf=navigate - - ms - -
0|server | GET /fresh?spf=navigate - - ms - -
0|server | GET /series/58dc032ef5ac4394447e7a3c - - ms - -
0|server | GET / - - ms - -
0|server | GET /featured?spf=navigate - - ms - -
0|server | GET / - - ms - -
0|server | GET /featured - - ms - -
0|server | GET / - - ms - -
0|server | GET /ping - - ms - -
如你所见。没有错误。有任何想法吗?
还要注意 / ping是一个应该返回状态200的路由。没有db查询,没有任何内容。最简单的响应可能,但也失败了。
更新 尝试使用不同的浏览器+ chrome的隐身功能来验证它不是缓存问题。仍然没有回应。
PM2 Monit :
Mem: 140MB CPU:0%
Loop delay 1.46ms
CPU配置文件:
堆快照
更新4/2/2017: 经过一些调试后,我认为它与远程服务器断开连接......一旦我解决了这个问题,我就会发布回复。
2017年4月3日更新 这是我的mongooose连接代码:
mongoose.connect(configDB.url,{user:configDB.user,pass:configDB.pwd,server:{reconnectTries:60,reconnectInterval:1000}});
// CONNECTION EVENTS
// When successfully connected
mongoose.connection.on('connected', function () {
console.log('Mongoose default connection open to ' + configDB.url);
});
// If the connection throws an error
mongoose.connection.on('error',function (err) {
console.log('Mongoose default connection error: ' + err);
console.log("Disconnecting")
mongoose.disconnect();
});
// When the connection is disconnected
mongoose.connection.on('disconnected', function () {
console.log('Mongoose default connection disconnected');
//It automatically reconnects with not issues
});
问题是,当我的问题发生时,这些听众中没有一个会开火。没有抛出任何错误或异常。没有触发断开。 Just Halts ..
答案 0 :(得分:0)
如果您可以分享您的代码,以便我们更清楚地了解问题,那会更好。
如果你正在使用express,那可能只是app.use的错误排序,或者你可能有错误的中间件。您可以使用调试器或只是找出服务器崩溃的请求并给它一个修复程序。
答案 1 :(得分:0)
我也遇到了类似的问题,重启系统后问题解决了。