【发布时间】:2015-02-28 09:04:38
【问题描述】:
我使用 Hapi.js 作为 API 开发的框架,但在极少数情况下会出现以下错误。
2015-02-08T12:32:38.073Z - verbose: err.stack > Error: Already closed
at Object.exports.create (/var/www/ragchewAppServerSrc/ragchew_prod/ragchews/node_modules/hapi/node_modules/boom/lib/index.js:21:17)
at Object.exports.internal (/var/www/ragchewAppServerSrc/ragchew_prod/ragchews/node_modules/hapi/node_modules/boom/lib/index.js:252:92)
at /var/www/ragchewAppServerSrc/ragchew_prod/ragchews/node_modules/hapi/lib/request.js:297:34
at iterate (/var/www/ragchewAppServerSrc/ragchew_prod/ragchews/node_modules/hapi/node_modules/items/lib/index.js:35:13)
at done (/var/www/ragchewAppServerSrc/ragchew_prod/ragchews/node_modules/hapi/node_modules/items/lib/index.js:27:25)
at validate (/var/www/ragchewAppServerSrc/ragchew_prod/ragchews/node_modules/hapi/lib/auth.js:283:20)
at finish (/var/www/ragchewAppServerSrc/ragchew_prod/ragchews/node_modules/hapi/lib/protect.js:45:21)
at wrapped (/var/www/ragchewAppServerSrc/ragchew_prod/ragchews/node_modules/hapi/node_modules/hoek/lib/index.js:798:20)
at root (/var/www/ragchewAppServerSrc/ragchew_prod/ragchews/node_modules/hapi/lib/auth.js:198:50)
at /var/www/ragchewAppServerSrc/ragchew_prod/ragchews/src/middlewares/auth/ragchew_auth_strategy.js:75:28
2015-02-08T12:32:38.073Z - verbose: err > {"isBoom":true,"output":{"statusCode":500,"payload":{"statusCode":500,"error":"Internal Server
无法在我们的测试环境中重现此问题,我也不了解此错误的根本原因。
如果有人强调框架生成此错误的原因/时间,那将非常有帮助。
在我们的代码中,当我们尝试从“身份验证插件”发回回复时会发生此错误。我们正在使用基本身份验证方案。
出现问题的示例 sn-p 是:
exports.register = function (plugin, options, next) {
plugin.auth.scheme('basic', function (server, options) {
var settings = options;
// some code here
var scheme = {
authenticate: function (request, reply) {
// some code here
// assign access token value to token here.
settings.validateFunc.call(request, token, function (err, isValid, credentials) {
// handle error here.
return reply(null, { credentials: credentials }); // error occurs on this line
});
}
};
return scheme;
});
next();
};
【问题讨论】:
-
这部分代码看起来不错。我认为问题将出在其他地方。您也可以添加“这里的一些代码”部分吗?
-
其实代码很多,所以我更想知道什么时候抛出这个错误,以便我自己解决问题。
-
你用的是哪个hapi版本?
-
我使用的是7.0.0版本