Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't destroy incoming requests during the stopping phase #4530

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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