Skip to content

Commit e28094f

Browse files
committed
Fix cache stop error handling. Closes hapijs#3711
1 parent 4f53938 commit e28094f

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/core.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,10 @@ exports = module.exports = internals.Core = class {
359359
await this._unlisten(options);
360360
}
361361

362-
this.caches.forEach((cache) => cache.client.stop());
362+
const caches = [];
363+
this.caches.forEach((cache) => caches.push(cache.client.stop()));
364+
await Promise.all(caches);
365+
363366
await this.events.emit('stop');
364367
this.heavy.stop();
365368
await this._invoke('onPostStop');

test/core.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,23 @@ describe('Core', () => {
531531
await expect(server.stop()).to.reject('Cannot stop server while in stopping phase');
532532
await stopping;
533533
});
534+
535+
it('errors on bad cache stop', async () => {
536+
537+
const cache = {
538+
engine: {
539+
start: function () { },
540+
stop: function () {
541+
542+
throw new Error('oops');
543+
}
544+
}
545+
};
546+
547+
const server = Hapi.server({ cache });
548+
await server.start();
549+
await expect(server.stop()).to.reject('oops');
550+
});
534551
});
535552

536553
describe('_init()', () => {

0 commit comments

Comments
 (0)