登录到控制台时出现 nodejs 错误

nodejs error on logging to console

我创建了一个插件 stubbydb,它 运行 在本地机器上运行良好。但是,当 运行使用 jenkins 在远程服务器上运行时,出现以下错误。

2016-03-16T10:58:10.745Z - error: uncaughtException: write EPIPE date=Wed Mar 16 2016 10:58:10 GMT+0000 (GMT), pid=23729, uid=501, gid=500, cwd=/home/deployment, execPath=/usr/local/node/node-v5.2.0/bin/node, version=v5.2.0, argv=[/usr/local/node/node-v5.2.0/bin/node, /usr/local/node/node-default/bin/stubbydb, -d, /tmp/soa-simulator, -p, 7777, -s, /tmp/soa-simulator/], rss=22597632, heapTotal=12671264, heapUsed=8094384, loadavg=[1.7158203125, 0.68505859375, 0.27392578125], uptime=5615485, trace=[column=11, file=util.js, function=Object.exports._errnoException, line=856, method=exports._errnoException, native=false, column=20, file=util.js, function=exports._exceptionWithHostPort, line=879, method=_exceptionWithHostPort, native=false, column=14, file=net.js, function=WriteWrap.afterWrite, line=764, method=afterWrite, native=false], stack=[Error: write EPIPE,     at Object.exports._errnoException (util.js:856:11),     at exports._exceptionWithHostPort (util.js:879:20),     at WriteWrap.afterWrite (net.js:764:14)]

2016-03-16T10:58:36.696Z - error: uncaughtException: This socket is closed. date=Wed Mar 16 2016 10:58:36 GMT+0000 (GMT), pid=23729, uid=501, gid=500, cwd=/home/deployment, execPath=/usr/local/node/node-v5.2.0/bin/node, version=v5.2.0, argv=[/usr/local/node/node-v5.2.0/bin/node, /usr/local/node/node-default/bin/stubbydb, -d, /tmp/soa-simulator, -p, 7777, -s, /tmp/soa-simulator/], rss=25243648, heapTotal=12671264, heapUsed=8775480, loadavg=[1.443359375, 0.7080078125, 0.291015625], uptime=5615511, trace=[column=19, file=net.js, function=Socket._writeGeneric, line=641, method=_writeGeneric, native=false, column=8, file=net.js, function=Socket._write, line=695, method=_write, native=false, column=12, file=_stream_writable.js, function=doWrite, line=293, method=null, native=false, column=5, file=_stream_writable.js, function=writeOrBuffer, line=279, method=null, native=false, column=11, file=_stream_writable.js, function=Socket.Writable.write, line=208, method=Writable.write, native=false, column=40, file=net.js, function=Socket.write, line=619, method=write, native=false, column=16, file=console.js, function=Console.log, line=37, method=log, native=false, column=12, file=/usr/local/node/node-v5.2.0/lib/node_modules/stubby-db/js/stubbyDB.js, function=, line=29, method=null, native=false, column=13, file=events.js, function=emitNone, line=68, method=null, native=false, column=7, file=events.js, function=IncomingMessage.emit, line=167, method=emit, native=false], stack=[Error: This socket is closed.,     at Socket._writeGeneric (net.js:641:19),     at Socket._write (net.js:695:8),     at doWrite (_stream_writable.js:293:12),     at writeOrBuffer (_stream_writable.js:279:5),     at Socket.Writable.write (_stream_writable.js:208:11),     at Socket.write (net.js:619:40),     at Console.log (console.js:37:16),     at IncomingMessage.<anonymous> (/usr/local/node/node-v5.2.0/lib/node_modules/stubby-db/js/stubbyDB.js:29:12),     at emitNone (events.js:68:13),     at IncomingMessage.emit (events.js:167:7)]

所以直到 jenkins 的工作是 运行ning stubbydb 响应。但是一旦詹金斯的工作完成。它停止工作。并在 console.log() 语句中给出错误。

如果我登录到服务器并在节点控制台上执行 console.log("something")。我没有看到错误。此外,如果我 运行 stubbydb 在登录后直接出现而不是 jenkins。它工作正常。

可能是什么原因?我应该避免写入控制台吗?

尝试这样做...

FunctionThrowingException().on("error", function(){
       //Handle exception here
});

关于抛出异常的函数。我曾经遇到过这个问题,但是使用了 Node.js 的另一个应用程序。处理异常应该可以完成工作。

P.S。这不是确切的解决方案,因为您没有提供完整的代码。所以,只要接受这个想法并检查你的代码。应该有帮助。

我没有发现应用程序有任何问题。问题自动解决。它似乎与詹金斯工作或服务器设置有关。但是我已经删除了所有默认 console.log 并按需进行日志记录。因此,如果有人遇到同样的问题,只需关闭日志记录即可。