Hapi 8.8.0 (Also happens on 8.2.0 and 6.11.1)
Throwing an error breaks the request lifecycle when using a cached server method.
Only the first request is returned and the server is stuck.
This only happens when multiple connections are active at the same time.
- can be demonstrated by changing
Async.times to Async.timesSeries
The expected console output is:
0: Complete
1: Complete
The actual console output is:
0: Complete
Example Code:
var Hapi = require('hapi');
var Async = require('async');
var internals = {};
var server = new Hapi.Server();
server.connection({ port: 3000 });
server.method('someCachedMethod',
function(callback){
return callback(null, 3);
},
{ cache: {
expiresIn: 20,
staleIn: 10,
staleTimeout: 1
}}
);
server.ext('onPreResponse', function(request, reply){
console.log(request.params.id + ": Response handler called");
reply.continue();
});
server.route({
method: 'GET',
path: '/{id}',
config: {
handler: function (request, reply) {
request.server.methods.someCachedMethod(function(err, num) {
console.log(request.params.id + ": Triggering unhandled exception");
throw new Error("Test Error!");
});
}
}
});
server.start(function (err) {
if (err) console.log(err);
console.log('server running at: ' + server.info.uri);
Async.times(2, function(n, next){
console.log(n + ": Triggering request");
server.inject("/" + n, function(res){
console.log(n + ": Complete");
return next();
});
}, function(err){
console.log("Test Complete");
});
});
Hapi 8.8.0 (Also happens on 8.2.0 and 6.11.1)
Throwing an error breaks the request lifecycle when using a cached server method.
Only the first request is returned and the server is stuck.
This only happens when multiple connections are active at the same time.
Async.timestoAsync.timesSeriesThe expected console output is:
0: Complete
1: Complete
The actual console output is:
0: Complete
Example Code: