在调试模式下,如果我的服务器在相当长的一段时间内(通常是整夜)处于运行状态,那么我来看看。
events.js:174
throw er; // Unhandled 'error' event
^
Error [ERR_STREAM_WRITE_AFTER_END]: write after end
at writeAfterEnd (_stream_writable.js:243:12)
at Socket.Writable.write (_stream_writable.js:291:5)
at Connection.write (C:\Git\webUI\development\node_modules\mongoose\node_modules\mongodb-core\lib\connection\connection.js:734:57)
at C:\Git\webUI\development\node_modules\mongoose\node_modules\mongodb-core\lib\connection\pool.js:1563:44
at waitForAuth (C:\Git\webUI\development\node_modules\mongoose\node_modules\mongodb-core\lib\connection\pool.js:1417:40)
at C:\Git\webUI\development\node_modules\mongoose\node_modules\mongodb-core\lib\connection\pool.js:1425:5
at C:\Git\webUI\development\node_modules\mongoose\node_modules\mongodb-core\lib\connection\pool.js:1278:23
at process._tickCallback (internal/process/next_tick.js:61:11)
Emitted 'error' event at:
at writeAfterEnd (_stream_writable.js:245:10)
at Socket.Writable.write (_stream_writable.js:291:5)
[... lines matching original stack trace ...]
at process._tickCallback (internal/process/next_tick.js:61:11)
Waiting for the debugger to disconnect...
它没有指向代码中的任何地方,这可能是错误的根源。
Mongo连接功能:
function mongoConnect() {
var options = {
keepAlive: 1,
connectTimeoutMS: 5000, // ms. default = 30000
reconnectTries: 1000, // default = 30
reconnectInterval: 5000, // ms. default = 1000
family: 4, // force IPV4 to speed up connection
// set this to remove a deprecation warning. See mongoose issue: 6890
useCreateIndex: true,
useNewUrlParser: true,
};
try {
mainLogger.info(`connecting to: mongodb://${process.env.mongoServerIP}:${process.env.mongoServerPort}/${process.env.mongoDatabaseName}`);
mongoose.connect(`mongodb://${process.env.mongoServerIP}:${process.env.mongoServerPort}/${process.env.mongoDatabaseName}`, options);
} catch (error) {
mainLogger.error(`Error while connecting to mongo DB: ${error}`);
}
return mongoose.connection;
}
Mongo事件处理程序:
mongoConnect()
.on("error", function (...messages) {
mainLogger.error(`Mongo connection error: ${JSON.stringify(messages)}`);
fatalError.error = true;
fatalError.mongoConnectError = true;
fatalError.mongoErrorMessages = messages;
mainLogger.error(messages);
listen();
})
.on("disconnected", mongoConnect())
.once("open", function (...messages) {
mainLogger.info("Mongo connected successfully.");
fatalError.error = false;
fatalError.mongoConnectError = false;
fatalError.mongoErrorMessages = messages;
if (messages.length > 0)
mainLogger.info(messages);
listen();
});
任何人都可以提供问题根源的任何指示吗?