Skip to content

Commit a033325

Browse files
committed
Don't destroy incoming requests during the stopping phase
1 parent 22377ee commit a033325

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

.labrc.js

-9
This file was deleted.

lib/core.js

-6
Original file line numberDiff line numberDiff line change
@@ -506,12 +506,6 @@ exports = module.exports = internals.Core = class {
506506

507507
return (req, res) => {
508508

509-
// $lab:coverage:off$ $not:allowsStoppedReq$
510-
if (this.phase === 'stopping') {
511-
return req.destroy();
512-
}
513-
// $lab:coverage:on$ $not:allowsStoppedReq$
514-
515509
// Create request
516510

517511
const request = Request.generate(this.root, req, res, options);

test/core.js

+21
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const Hapi = require('..');
1919
const Hoek = require('@hapi/hoek');
2020
const Inert = require('@hapi/inert');
2121
const Lab = require('@hapi/lab');
22+
const Teamwork = require('@hapi/teamwork');
2223
const Vision = require('@hapi/vision');
2324
const Wreck = require('@hapi/wreck');
2425

@@ -938,6 +939,26 @@ describe('Core', () => {
938939
expect(server._core.started).to.equal(false);
939940
});
940941

942+
it('allows incoming requests during the stopping phase', async () => {
943+
944+
const team = new Teamwork.Team();
945+
946+
const server = Hapi.server();
947+
server.route({ method: 'GET', path: '/', handler: () => 'ok' });
948+
server.ext('onPreStop', () => team.work);
949+
950+
await server.start();
951+
const stop = server.stop();
952+
const { res, payload } = await Wreck.get(`http://localhost:${server.info.port}`);
953+
954+
team.attend(); // Allow server to finalize stop
955+
await stop;
956+
957+
expect(res.headers.connection).to.equal('close');
958+
expect(payload.toString()).to.equal('ok');
959+
expect(server._core.started).to.equal(false);
960+
});
961+
941962
it('finishes in-progress requests and ends connection', async () => {
942963

943964
let stop;

0 commit comments

Comments
 (0)