Skip to content

Commit

Permalink
Don't destroy incoming requests during the stopping phase
Browse files Browse the repository at this point in the history
  • Loading branch information
kanongil authored and Marsup committed Oct 24, 2024
1 parent 286cea9 commit b720834
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
9 changes: 0 additions & 9 deletions .labrc.js

This file was deleted.

6 changes: 0 additions & 6 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,6 @@ exports = module.exports = internals.Core = class {

return (req, res) => {

// $lab:coverage:off$ $not:allowsStoppedReq$
if (this.phase === 'stopping') {
return req.destroy();
}
// $lab:coverage:on$ $not:allowsStoppedReq$

// Create request

const request = Request.generate(this.root, req, res, options);
Expand Down
21 changes: 21 additions & 0 deletions test/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const Hapi = require('..');
const Hoek = require('@hapi/hoek');
const Inert = require('@hapi/inert');
const Lab = require('@hapi/lab');
const Teamwork = require('@hapi/teamwork');
const Vision = require('@hapi/vision');
const Wreck = require('@hapi/wreck');

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

it('allows incoming requests during the stopping phase', async () => {

const team = new Teamwork.Team();

const server = Hapi.server();
server.route({ method: 'GET', path: '/', handler: () => 'ok' });
server.ext('onPreStop', () => team.work);

await server.start();
const stop = server.stop();
const { res, payload } = await Wreck.get(`http://localhost:${server.info.port}`);

team.attend(); // Allow server to finalize stop
await stop;

expect(res.headers.connection).to.equal('close');
expect(payload.toString()).to.equal('ok');
expect(server._core.started).to.equal(false);
});

it('finishes in-progress requests and ends connection', async () => {

let stop;
Expand Down

0 comments on commit b720834

Please sign in to comment.