Skip to content

Commit 28e1648

Browse files
RaisinTentargos
authored andcommitted
async_hooks,doc: replace process.stdout.fd with 1
This stops "RangeError: Maximum call stack size exceeded". PR-URL: #38382 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent c1d9b5b commit 28e1648

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

doc/api/async_hooks.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -271,16 +271,18 @@ created, while `triggerAsyncId` shows *why* a resource was created.
271271
The following is a simple demonstration of `triggerAsyncId`:
272272

273273
```js
274+
const { fd } = process.stdout;
275+
274276
async_hooks.createHook({
275277
init(asyncId, type, triggerAsyncId) {
276278
const eid = async_hooks.executionAsyncId();
277279
fs.writeSync(
278-
process.stdout.fd,
280+
fd,
279281
`${type}(${asyncId}): trigger: ${triggerAsyncId} execution: ${eid}\n`);
280282
}
281283
}).enable();
282284

283-
require('net').createServer((conn) => {}).listen(8080);
285+
net.createServer((conn) => {}).listen(8080);
284286
```
285287

286288
Output when hitting the server with `nc localhost 8080`:
@@ -322,33 +324,35 @@ callback to `listen()` will look like. The output formatting is slightly more
322324
elaborate to make calling context easier to see.
323325

324326
```js
327+
const { fd } = process.stdout;
328+
325329
let indent = 0;
326330
async_hooks.createHook({
327331
init(asyncId, type, triggerAsyncId) {
328332
const eid = async_hooks.executionAsyncId();
329333
const indentStr = ' '.repeat(indent);
330334
fs.writeSync(
331-
process.stdout.fd,
335+
fd,
332336
`${indentStr}${type}(${asyncId}):` +
333337
` trigger: ${triggerAsyncId} execution: ${eid}\n`);
334338
},
335339
before(asyncId) {
336340
const indentStr = ' '.repeat(indent);
337-
fs.writeSync(process.stdout.fd, `${indentStr}before: ${asyncId}\n`);
341+
fs.writeSync(fd, `${indentStr}before: ${asyncId}\n`);
338342
indent += 2;
339343
},
340344
after(asyncId) {
341345
indent -= 2;
342346
const indentStr = ' '.repeat(indent);
343-
fs.writeSync(process.stdout.fd, `${indentStr}after: ${asyncId}\n`);
347+
fs.writeSync(fd, `${indentStr}after: ${asyncId}\n`);
344348
},
345349
destroy(asyncId) {
346350
const indentStr = ' '.repeat(indent);
347-
fs.writeSync(process.stdout.fd, `${indentStr}destroy: ${asyncId}\n`);
351+
fs.writeSync(fd, `${indentStr}destroy: ${asyncId}\n`);
348352
},
349353
}).enable();
350354

351-
require('net').createServer(() => {}).listen(8080, () => {
355+
net.createServer(() => {}).listen(8080, () => {
352356
// Let's wait 10ms before logging the server started.
353357
setTimeout(() => {
354358
console.log('>>>', async_hooks.executionAsyncId());

0 commit comments

Comments
 (0)