Tag: 崩溃

我如何有目的地崩溃我的node.js服务器?

我如何有目的地崩溃我的node.js服务器? (当发生某些致命的错误时,我想这样做,所以立即引起我的注意并予以修复) 我已经在这里看到这个post,但我不想使用C模块或运行一个无限循环(因为我的应用程序运行在一个服务器上,我花了CPU使用的时间)这意味着这将是非常昂贵的难以最大限度地利用CPU。 我已经尝试使用process.exit和process.abort,但只closures它被调用的模块。 例如,我的服务器是通过调用node main.js启动的,它需要几个自定义模块,我已经写在其他文件中。 如果在其中一个文件中调用process.exit或process.abort,则会正确closures在其他文件中发生的任何事情,但不会closures整个节点服务器和main.js. 这里是代码中发生的一个简单的例子: //crashServer.js var exampleVar; module.exports = function(){ if (!exampleVar){ var err = new Error("An error has occured"); Error.captureStackTrace(err); //error logging code console.log("An error has occured and the server will now crash."); process.exit(); } }; //main.js var crashServer = require("./crashServer.js"); crashServer(); while (true){ console.log("Server still running"); } 如果我跑 node […]

在Excel生成文件崩溃之前,Nodejs V8 GC正在通知

我在我的应用程序中使用xlsx图表节点模块。 该模块使用内存从您的数据点生成Excel图表。 有时当我有太多的数据点我的节点js应用程序崩溃,如下所示: <— Last few GCs —> [6420:000000CD560122F0] 77691 ms: Mark-sweep 2047.4 (2086.4) -> 2047.4 (2086.4) MB, 1235.2 / 0.1 ms allocation failure GC in old space requested [6420:000000CD560122F0] 79246 ms: Mark-sweep 2047.4 (2086.4) -> 2047.4 (2086.4) MB, 1141.2 / 0.0 ms last resort [6420:000000CD560122F0] 80808 ms: Mark-sweep 2047.4 (2086.4) -> 2047.4 (2086.4) MB, […]

SocketRocket崩溃Node.js WebSocket

我写了一个简单的Node.js WebSocket聊天服务器 。 要运行服务器,我正在使用一个只包含以下行的Procfile : foreman start chat: npm start 。 我还写了一个使用SocketRocket连接到上述服务器的iPhone应用程序。 在applicationDidEnterBackground: ,我在webSocket上调用close 。 而且,在applicationWillEnterForeground: ,我重新创build了webSocket并open 。 当进入后台或前台时,iPhone应用程序似乎崩溃与服务器的错误: chat.1 | events.js:74 chat.1 | throw TypeError('Uncaught, unspecified "error" event.'); chat.1 | ^ chat.1 | TypeError: Uncaught, unspecified "error" event. chat.1 | at TypeError (<anonymous>) chat.1 | at WebSocket.EventEmitter.emit (events.js:74:15) chat.1 | at Receiver.self._receiver.onerror (~/Projects/Chat/node_modules/ws/lib/WebSocket.js:719:10) chat.1 […]

Node.js(&MongoDB)服务器崩溃,数据库操作中途?

我有一个node.js应用程序与mongodb后端去一周生产,我对如何处理应用程序崩溃和重新启动有一些怀疑。 说我有一个简单的路线/followUser我有2个数据库操作 /followUser —–>Update User1 Document.followers = User2 —–>Update User2 Document.followers = User1 —–>Some other mongodb(via mongoose)operation 如果发生服务器崩溃(由于电源故障或远程mongodb服务器closures),会发生什么情况,如下所示: —–>Update User1 Document.followers = User2 SERVER CRASHED , FOREVER RESTARTS NODE 下面的这些操作会发生什么? 系统现在处于不一致的状态,每当我要求User2的追随者时,我可能会有错误 —–>Update User2 Document.followers = User1 —–>Some other mongodb(via mongoose)operation 另外请推荐良好的日志logging,并重新启动/监视模块的Linux应用程序运行。 现在即时使用域来捕获exception,做server.close,但在process.exit()之前,我想确保所有的数据库事务完成,我可以通过testing,如果事件循环是空的或不(如何? ),然后process.exit(1)?

NodeJS崩溃与多个请求

我的nodejs服务器实时地随机崩溃(并且总是在Web Stress Tool上使用10+线程请求)。 以下是我认为是根本原因的代码。 main.js ——– app = express(): ——— app.get('/image/*', actions.download); actions.js var request = require('request'); exports.download = function(req, res){ var url = <Amazon s3 URL>; req.pipe(request(url)).pipe(res); }; 当服务器崩溃时,我在nohup中得到错误 stream.js:94 throw er; // Unhandled stream error in pipe. ^ Error: socket hang up at createHangUpError (http.js:1476:15) at Socket.socketOnEnd [as onend] (http.js:1572:23) at Socket.g (events.js:180:16) […]

节点JS进程崩溃没有错误logging

我试图运行一个非常简单的实现使用Express服务EJS内容的节点JS服务器。 当我启动服务器,它运行得很好,但一段时间后意外崩溃。 有时会在半小时内崩溃,而其他时间则会一次停留4-6小时。 我似乎无法确定错误的来源,因为我的日志不包含任何堆栈跟踪。 我已经采取了这个答案的build议 ,我有这个: process.on('uncaughtException', function (exception) { console.log(exception); // to see your exception details in the console }); 我也重载了console方法来login到一个文件,如下所示: console.log = function(d) { log(d); }; console.error = function(d) { log(d); }; function log(message) { log_file.write(util.format(message) + '\n'); log_stdout.write(util.format(message) + '\n'); } 不过,服务器崩溃而不报告任何东西。 我也试图创build一个节点domain : var domain = require('domain'); var d = domain.create(); […]

Heroku的应用程序不断崩溃根据日志…为什么?

只要我部署了应用程序,并推出了本教程中的代码: http : //blog.superpat.com/2011/06/14/node-js-chat-demo-on-heroku/ 我收到了这个来自heroku的错误:“应用程序发生错误,您的页面无法投放,请稍后重试。 如果您是应用程序所有者,请查看日志以获取详细信息。“ 这是我得到的日志错误: 2013-05-07T12:46:21.537628+00:00 app[web.1]: module.js:340 2013-05-07T12:46:21.537946+00:00 app[web.1]: throw err; 2013-05-07T12:46:21.538118+00:00 app[web.1]: ^ 2013-05-07T12:46:21.540143+00:00 app[web.1]: Error: Cannot find module 'pg' 2013-05-07T12:46:21.540143+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:338:15) 2013-05-07T12:46:21.540143+00:00 app[web.1]: at Function.Module._load (module.js:280:25) 2013-05-07T12:46:21.540143+00:00 app[web.1]: at require (module.js:380:17) 2013-05-07T12:46:21.540143+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:22:10) 2013-05-07T12:46:21.540143+00:00 app[web.1]: at Module._compile (module.js:456:26) 2013-05-07T12:46:21.540143+00:00 app[web.1]: at Object.Module._extensions..js (module.js:474:10) 2013-05-07T12:46:21.540143+00:00 […]

为什么express的默认error handling程序行为将堆栈跟踪返回给客户端?

我试图让我的http api服务器中的error handling工作正常,我不明白节点的error handling行为。 我已经定义了我自己的错误对象,如下所示: function ServerError(statusCode, err, message) { this.status = statusCode; if (err != undefined) { this.err = err; if (message != undefined) { this.message = message; } else { this.message = err.message || err; } } } ServerError.prototype = new Error(); 我使用这样的对象,无论是在中间件或处理程序: function forceError() { return function(req, res, next) { next(new ServerError(500, […]

NodeJS崩溃:当找不到文档时,Mongoose findById()不会抛出错误

我试图研究这个问题的原因。 这很可能是我对Mongoose工作方式的一个误解。 我正在试验用REST风格创build一个CRUD后端。 GET,PUT,POST都似乎工作。 不过,对于DELETE动词的问题,我有点不知所措。 问题 我用邮差input了一些伪造的数据,一切进展顺利。 所以我复制了一个我的logging的_id字段,试图删除。 当我发送DELETE请求时,成功消息传出,logging确实从mongo中删除。 但是,在删除其他logging之后,我决定尝试用已删除文档的_id删除logging。 我发送了一个DELETE请求到'api / brothers / 57280602953cff031f21ad9c' 结果NodeJS崩溃! 这是相关的服务器代码: // DELETE a brother by id app.delete('/api/brothers/:id', function(req, res) { Brother.findById(req.params.id, function(err, brother) { if (err) { // error finding brother res.json(err); } else { // remove record brother.remove(function(err, brother) { if (err) { // error removing! res.send(err); […]

奇怪的错误消息在Node.js

最近我得到了很多奇怪的错误消息,现在我甚至无法启动app.js。 以下是什么意思,有谁知道如何解决? node.js:201 throw e; // process.nextTick error, or 'error' event on first tick ^ TypeError: Cannot read property 'port' of null at Object.<anonymous> (/Users/henrikpetersson81/node/last/test4/app.js:15:64) at Module._compile (module.js:441:26) at Object..js (module.js:459:10) at Module.load (module.js:348:31) at Function._load (module.js:308:12) at Array.0 (module.js:479:10) at EventEmitter._tickCallback (node.js:192:40)