Skip to content

http,https,http2: make async disposers idempotent #58832

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
6 changes: 0 additions & 6 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const {
ObjectSetPrototypeOf,
ReflectApply,
Symbol,
SymbolAsyncDispose,
SymbolFor,
} = primordials;

Expand Down Expand Up @@ -82,7 +81,6 @@ const {
const {
assignFunctionName,
kEmptyObject,
promisify,
} = require('internal/util');
const {
validateInteger,
Expand Down Expand Up @@ -580,10 +578,6 @@ Server.prototype.close = function close() {
return this;
};

Server.prototype[SymbolAsyncDispose] = assignFunctionName(SymbolAsyncDispose, async function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm does this make this a semver-major? This becomes a user observable change and if someone happens to be using an ERM polyfill I can imagine removing this breaking things.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I forgot that disposers graduated from experimental state since v24.2.0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to split this into two patches, one to make the existing http* overrides idempotent, and another semver-major one to remove them?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think since they are stable, making them not throw would technically already be a breaking change. If not, splitting is indeed better.
Another option is separate backport PRs changing only the overrides.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In most cases making an error into a non-error is not a breaking change. Obviously it can be, but so can adding a new function or option.

(I don't know if node has a policy to the contrary, just speaking generally.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we've generally treated removing throws as something less than semver-major, and adding a throw as always semver-major, but often it's a case-by-case determination.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this PR, rather than removing the asyncDispose, let's add a doc-only deprecation and make this one semver-patch.

Then, separately in another semver-major PR, we can runtime deprecate the asyncDispose for the next major. Then once 25.0.0 is cut later this year we can open another semver-major that moves it to EOL.

Painful, yes, I know.

await promisify(this.close).call(this);
});

Server.prototype.closeAllConnections = function closeAllConnections() {
if (!this[kConnections]) {
return;
Expand Down
6 changes: 0 additions & 6 deletions lib/https.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ const {
ObjectSetPrototypeOf,
ReflectApply,
ReflectConstruct,
SymbolAsyncDispose,
} = primordials;

const {
assertCrypto,
kEmptyObject,
promisify,
} = require('internal/util');
assertCrypto();

Expand Down Expand Up @@ -116,10 +114,6 @@ Server.prototype.close = function close() {
return this;
};

Server.prototype[SymbolAsyncDispose] = async function() {
await FunctionPrototypeCall(promisify(this.close), this);
};

/**
* Creates a new `https.Server` instance.
* @param {{
Expand Down
5 changes: 0 additions & 5 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const {
SafeMap,
SafeSet,
Symbol,
SymbolAsyncDispose,
SymbolDispose,
Uint32Array,
Uint8Array,
Expand Down Expand Up @@ -3346,10 +3345,6 @@ class Http2Server extends NETServer {
ReflectApply(NETServer.prototype.close, this, arguments);
closeAllSessions(this);
}

async [SymbolAsyncDispose]() {
await promisify(super.close).call(this);
}
}

Http2Server.prototype[EventEmitter.captureRejectionSymbol] = function(
Expand Down
5 changes: 3 additions & 2 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const {
const { isUint8Array } = require('internal/util/types');
const { queueMicrotask } = require('internal/process/task_queues');
const {
assignFunctionName,
guessHandleType,
isWindows,
kEmptyObject,
Expand Down Expand Up @@ -2391,12 +2392,12 @@ Server.prototype.close = function(cb) {
return this;
};

Server.prototype[SymbolAsyncDispose] = async function() {
Server.prototype[SymbolAsyncDispose] = assignFunctionName(SymbolAsyncDispose, async function() {
if (!this._handle) {
return;
}
await FunctionPrototypeCall(promisify(this.close), this);
};
});

Server.prototype._emitCloseIfDrained = function() {
debug('SERVER _emitCloseIfDrained');
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-http-server-async-dispose.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ const { kConnectionsCheckingInterval } = require('_http_server');
const server = createServer();

server.listen(0, common.mustCall(() => {
assert.strictEqual(server[Symbol.asyncDispose].name, '[Symbol.asyncDispose]');
server.on('close', common.mustCall());
server[Symbol.asyncDispose]().then(common.mustCall(() => {
assert(server[kConnectionsCheckingInterval]._destroyed);

// Disposer must be idempotent, subsequent call must not throw
server[Symbol.asyncDispose]().then(common.mustCall());
}));
}));
9 changes: 8 additions & 1 deletion test/parallel/test-http2-server-async-dispose.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ if (!common.hasCrypto)
common.skip('missing crypto');

const http2 = require('http2');
const assert = require('node:assert');

const server = http2.createServer();

server.listen(0, common.mustCall(() => {
assert.strictEqual(server[Symbol.asyncDispose].name, '[Symbol.asyncDispose]');
server.on('close', common.mustCall());
server[Symbol.asyncDispose]().then(common.mustCall());
server[Symbol.asyncDispose]().then(common.mustCall(() => {
assert.strictEqual(server._handle, null);

// Disposer must be idempotent, subsequent call must not throw
server[Symbol.asyncDispose]().then(common.mustCall());
}));
}));
4 changes: 4 additions & 0 deletions test/parallel/test-https-server-async-dispose.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ const { kConnectionsCheckingInterval } = require('_http_server');
const server = createServer();

server.listen(0, common.mustCall(() => {
assert.strictEqual(server[Symbol.asyncDispose].name, '[Symbol.asyncDispose]');
server.on('close', common.mustCall());
server[Symbol.asyncDispose]().then(common.mustCall(() => {
assert(server[kConnectionsCheckingInterval]._destroyed);

// Disposer must be idempotent, subsequent call must not throw
server[Symbol.asyncDispose]().then(common.mustCall());
}));
}));
Loading