Skip to content

Commit be1265f

Browse files
committed
doc: discourage AbortSignal cleanup for long-lived resources
Signed-off-by: Efe Karasakal <hi@efe.dev>
1 parent f4c85d5 commit be1265f

4 files changed

Lines changed: 91 additions & 0 deletions

File tree

‎doc/api/child_process.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ can be used to specify the character encoding used to decode the stdout and
242242
stderr output. If `encoding` is `'buffer'`, or an unrecognized character
243243
encoding, `Buffer` objects will be passed to the callback instead.
244244

245+
> Stability: 0 - Deprecated. Using the `signal` option to destroy long-lived
246+
> child process resources is documentation-only deprecated. See
247+
> [DEP0208](deprecations.md#dep0208-using-abortsignal-to-dispose-of-resources).
248+
245249
```cjs
246250
const { exec } = require('node:child_process');
247251
exec('cat *.js missing_file | wc -l', (error, stdout, stderr) => {
@@ -390,6 +394,10 @@ except that it does not spawn a shell by default. Rather, the specified
390394
executable `file` is spawned directly as a new process making it slightly more
391395
efficient than [`child_process.exec()`][].
392396

397+
> Stability: 0 - Deprecated. Using the `signal` option to destroy long-lived
398+
> child process resources is documentation-only deprecated. See
399+
> [DEP0208](deprecations.md#dep0208-using-abortsignal-to-dispose-of-resources).
400+
393401
The same options as [`child_process.exec()`][] are supported. Since a shell is
394402
not spawned, behaviors such as I/O redirection and file globbing are not
395403
supported.
@@ -585,6 +593,10 @@ current process.
585593
The `shell` option available in [`child_process.spawn()`][] is not supported by
586594
`child_process.fork()` and will be ignored if set.
587595

596+
> Stability: 0 - Deprecated. Using the `signal` option to destroy long-lived
597+
> child process resources is documentation-only deprecated. See
598+
> [DEP0208](deprecations.md#dep0208-using-abortsignal-to-dispose-of-resources).
599+
588600
If the `signal` option is enabled, calling `.abort()` on the corresponding
589601
`AbortController` is similar to calling `.kill()` on the child process except
590602
the error passed to the callback will be an `AbortError`:
@@ -735,6 +747,10 @@ process, the default is [`process.env`][].
735747
736748
`undefined` values in `env` will be ignored.
737749
750+
> Stability: 0 - Deprecated. Using the `signal` option to destroy long-lived
751+
> child process resources is documentation-only deprecated. See
752+
> [DEP0208](deprecations.md#dep0208-using-abortsignal-to-dispose-of-resources).
753+
738754
Example of running `ls -lh /usr`, capturing `stdout`, `stderr`, and the
739755
exit code:
740756

‎doc/api/deprecations.md‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4643,6 +4643,73 @@ underlying stream are emitted from `req`. On the write-side you can use
46434643
`res.writableFinished` to confirm whether the response was written
46444644
successfully before the response closed.
46454645
4646+
### DEP0208: Using `AbortSignal` to dispose of resources
4647+
4648+
<!-- YAML
4649+
changes:
4650+
- version: REPLACEME
4651+
pr-url: https://github.com/nodejs/node/pull/99999
4652+
description: Documentation-only deprecation.
4653+
-->
4654+
4655+
Type: Documentation-only
4656+
4657+
Using `AbortSignal` to destroy long-lived resources is deprecated. Prefer
4658+
`using` for resource cleanup.
4659+
4660+
`AbortSignal` is still a good fit for canceling actions, propagating
4661+
cancellation from the outside, and timeouts.
4662+
4663+
```js
4664+
// Deprecated
4665+
const ac = new AbortController();
4666+
const server = http.createServer(handler);
4667+
server.listen({ port: 3000, signal: ac.signal });
4668+
4669+
await doWork();
4670+
ac.abort();
4671+
```
4672+
4673+
```js
4674+
// Use this instead
4675+
await using server = http.createServer(handler);
4676+
server.listen(3000);
4677+
4678+
await doWork();
4679+
```
4680+
4681+
```js
4682+
// Deprecated
4683+
const ac = new AbortController();
4684+
const stream = addAbortSignal(ac.signal, fs.createReadStream(file));
4685+
4686+
await consume(stream);
4687+
ac.abort();
4688+
```
4689+
4690+
```js
4691+
// Use this instead
4692+
await using stream = fs.createReadStream(file);
4693+
4694+
await consume(stream);
4695+
```
4696+
4697+
```js
4698+
// Deprecated
4699+
const ac = new AbortController();
4700+
const child = spawn(command, args, { signal: ac.signal });
4701+
4702+
await doWork();
4703+
ac.abort();
4704+
```
4705+
4706+
```js
4707+
// Use this instead
4708+
using child = spawn(command, args);
4709+
4710+
await doWork();
4711+
```
4712+
46464713
[DEP0142]: #dep0142-repl_builtinlibs
46474714
[DEP0156]: #dep0156-aborted-property-and-abort-aborted-event-in-http
46484715
[NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf

‎doc/api/net.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,10 @@ Otherwise, if `path` is specified, it behaves the same as
588588
[`server.listen(path[, backlog][, callback])`][`server.listen(path)`].
589589
If none of them is specified, an error will be thrown.
590590

591+
> Stability: 0 - Deprecated. Using the `signal` option to destroy long-lived
592+
> server resources is documentation-only deprecated. See
593+
> [DEP0208](deprecations.md#dep0208-using-abortsignal-to-dispose-of-resources).
594+
591595
If `exclusive` is `false` (default), then cluster workers will use the same
592596
underlying handle, allowing connection handling duties to be shared. When
593597
`exclusive` is `true`, the handle is not shared, and attempted port sharing

‎doc/api/stream.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3555,6 +3555,10 @@ changes:
35553555
Attaches an AbortSignal to a readable or writeable stream. This lets code
35563556
control stream destruction using an `AbortController`.
35573557

3558+
> Stability: 0 - Deprecated. Using [`stream.addAbortSignal()`][] to destroy
3559+
> long-lived stream resources is documentation-only deprecated. See
3560+
> [DEP0208](deprecations.md#dep0208-using-abortsignal-to-dispose-of-resources).
3561+
35583562
Calling `abort` on the `AbortController` corresponding to the passed
35593563
`AbortSignal` will behave the same way as calling `.destroy(new AbortError())`
35603564
on the stream, and `controller.error(new AbortError())` for webstreams.

0 commit comments

Comments
 (0)