Skip to content

2020-11-04, Version 15.1.0 (Current), @targos

Compare
Choose a tag to compare
@targos targos released this 04 Nov 20:58
v15.1.0
2291e07

Notable Changes

Diagnostics channel (experimental module)

diagnostics_channel is a new experimental module that provides an API to create named channels to report arbitrary message data for diagnostics purposes.

With diagnostics_channel, Node.js core and module authors can publish contextual data about what they are doing at a given time. This could be the hostname and query string of a mysql query, for example. Just create a named channel with dc.channel(name) and call channel.publish(data) to send the data to any listeners to that channel.

const dc = require('diagnostics_channel');
const channel = dc.channel('mysql.query');

MySQL.prototype.query = function query(queryString, values, callback) {
  // Broadcast query information whenever a query is made
  channel.publish({
    query: queryString,
    host: this.hostname,
  });

  this.doQuery(queryString, values, callback);
};

Channels are like one big global event emitter but are split into separate objects to ensure they get the best performance. If nothing is listening to the channel, the publishing overhead should be as close to zero as possible. Consuming channel data is as easy as using channel.subscribe(listener) to run a function whenever a message is published to that channel.

const dc = require('diagnostics_channel');
const channel = dc.channel('mysql.query');

channel.subscribe(({ query, host }) => {
  console.log(`mysql query to ${host}: ${query}`);
});

The data captured can be used to provide context for what an app is doing at a given time. This can be used for things like augmenting tracing data, tracking network and filesystem activity, logging queries, and many other things. It's also a very useful data source for diagnostics tools to provide a clearer picture of exactly what the application is doing at a given point in the data they are presenting.

Contributed by Stephen Belanger #34895.

New child process 'spawn' event

Instances of ChildProcess now emit a new 'spawn' event once the child process has spawned successfully.

If emitted, the 'spawn' event comes before all other events and before any data is received via stdout or stderr.

The 'spawn' event will fire regardless of whether an error occurs within the spawned process.
For example, if bash some-command spawns successfully, the 'spawn' event will fire, though bash may fail to spawn some-command.
This caveat also applies when using { shell: true }.

Contributed by Matthew Francis Brunetti #35369.

Set the local address for DNS resolution

It is now possible to set the local IP address used by a Resolver instance to send its requests.
This allows programs to specify outbound interfaces when used on multi-homed
systems.

The resolver will use the v4 local address when making requests to IPv4 DNS servers, and the v6 local address when making requests to IPv6 DNS servers.

const { Resolver } = require('dns');

const resolver = new Resolver();

resolver.setLocalAddress('10.1.2.3');
// Equivalent to: resolver.setLocalAddress('10.1.2.3', '::0');

Contributed by Josh Dague #34824.

Control V8 coverage at runtime

The v8 module includes two new methods to control the V8 coverage started by the NODE_V8_COVERAGE environment variable.

With v8.takeCoverage(), it is possible to write a coverage report to disk on demand. This can be done multiple times during the lifetime of the process, and the execution counter will be reset on each call.
When the process is about to exit, one last coverage will still be written to disk, unless v8.stopCoverage() was invoked before.

The v8.stopCoverage() method allows to stop the coverage collection, so that V8 can release the execution counters and optimize code.

Contributed by Joyee Cheung #33807.

Analyze Worker's event loop utilization

Worker instances now have a performance property, with a single eventLoopUtilization method that can be used to gather information about the worker's event loop utilization between the 'online' and 'exit' events.

The method works the same way as perf_hooks eventLoopUtilization().

Contributed by Trevor Norris #35664.

Take a V8 heap snapshot just before running out of memory (experimental)

With the new --heapsnapshot-near-heap-limit=max_count experimental command line flag, it is now possible to automatically generate a heap snapshot when the V8 heap usage is approaching the heap limit. count should be a non-negative integer (in which case Node.js will write no more than max_count snapshots to disk).

When generating snapshots, garbage collection may be triggered and bring the heap usage down, therefore multiple snapshots may be written to disk before the Node.js instance finally runs out of memory. These heap snapshots can be compared to determine what objects are being allocated during the time consecutive snapshots are taken.

Generating V8 snapshots takes time and memory (both memory managed by the V8 heap and native memory outside the V8 heap). The bigger the heap is, the more resources it needs. Node.js will adjust the V8 heap to accommondate the additional V8 heap memory overhead, and try its best to avoid using up all the memory avialable to the process.

$ node --max-old-space-size=100 --heapsnapshot-near-heap-limit=3 index.js
Wrote snapshot to Heap.20200430.100036.49580.0.001.heapsnapshot
Wrote snapshot to Heap.20200430.100037.49580.0.002.heapsnapshot
Wrote snapshot to Heap.20200430.100038.49580.0.003.heapsnapshot

<--- Last few GCs --->

[49580:0x110000000]     4826 ms: Mark-sweep 130.6 (147.8) -> 130.5 (147.8) MB, 27.4 / 0.0 ms  (average mu = 0.126, current mu = 0.034) allocation failure scavenge might not succeed
[49580:0x110000000]     4845 ms: Mark-sweep 130.6 (147.8) -> 130.6 (147.8) MB, 18.8 / 0.0 ms  (average mu = 0.088, current mu = 0.031) allocation failure scavenge might not succeed


<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
....

Contributed by Joyee Cheung #33010.

Commits

Semver-minor commits

  • [8169902b40] - (SEMVER-MINOR) child_process: add ChildProcess 'spawn' event (Matthew Francis Brunetti) #35369
  • [548f91af2c] - (SEMVER-MINOR) dns: add setLocalAddress to Resolver (Josh Dague) #34824
  • [f861733bac] - (SEMVER-MINOR) http: report request start and end with diagnostics_channel (Stephen Belanger) #34895
  • [883ed4b7f1] - (SEMVER-MINOR) http2: add updateSettings to both http2 servers (Vincent Boivin) #35383
  • [b38a43d5d9] - (SEMVER-MINOR) lib: create diagnostics_channel module (Stephen Belanger) #34895
  • [a7f37bc725] - (SEMVER-MINOR) src: add --heapsnapshot-near-heap-limit option (Joyee Cheung) #33010
  • [7bfa872013] - (SEMVER-MINOR) v8: implement v8.stopCoverage() (Joyee Cheung) #33807
  • [15ffed5319] - (SEMVER-MINOR) v8: implement v8.takeCoverage() (Joyee Cheung) #33807
  • [221e28311f] - (SEMVER-MINOR) worker: add eventLoopUtilization() (Trevor Norris) #35664

Semver-patch commits

  • [d95013f399] - assert,repl: enable ecmaVersion 2021 in acorn parser (Michaël Zasso) #35827
  • [b11c7378e3] - build: fix lint-js-fix target (Antoine du Hamel) #35927
  • [a5fa849631] - build: add vcbuilt test-doc target (Antoine du Hamel) #35708
  • [34281cdaba] - build: turn off Codecov comments (bcoe) #35800
  • [a9c09246bb] - build: add license-builder GitHub Action (Tierney Cyren) #35712
  • [4447ff1162] - build,tools: gitHub Actions: use Node.js Fermium (Antoine du Hamel) #35840
  • [273e147017] - build,tools: add lint-js-doc target (Antoine du Hamel) #35708
  • [0ebf44b466] - crypto: pass empty passphrases to OpenSSL properly (Tobias Nießen) #35914
  • [644c416389] - crypto: rename check to createJob (Daniel Bevenius) #35858
  • [79a8fb62e6] - crypto: fixup scrypt regressions (James M Snell) #35821
  • [abd7c9447c] - crypto: fix webcrypto ECDH JWK import (Filip Skokan) #35855
  • [d3f1cde908] - deps: upgrade npm to 7.0.8 (Myles Borins) #35953
  • [55adee0947] - deps: upgrade npm to 7.0.7 (Luigi Pinca) #35908
  • [5cb77f2e79] - deps: upgrade to cjs-module-lexer@1.0.0 (Guy Bedford) #35928
  • [1303a1fca8] - deps: update to cjs-module-lexer@0.5.2 (Guy Bedford) #35901
  • [20accb08fa] - deps: upgrade to cjs-module-lexer@0.5.0 (Guy Bedford) #35871
  • [52a77db759] - deps: update acorn to v8.0.4 (Michaël Zasso) #35791
  • [e0a1541260] - deps: update to cjs-module-lexer@0.4.3 (Guy Bedford) #35745
  • [894419c1f4] - deps: V8: backport 4263f8a5e8e0 (Brian 'bdougie' Douglas) #35650
  • [564aadedac] - doc,src,test: revise C++ code for linter update (Rich Trott) #35719
  • [7c8b5e5e0e] - errors: do not call resolve on URLs with schemes (bcoe) #35903
  • [1cdfaa80f8] - events: add a few tests (Benjamin Gruenbaum) #35806
  • [f08e2c0213] - events: make abort_controller event trusted (Benjamin Gruenbaum) #35811
  • [438d9debfd] - events: make eventTarget.removeAllListeners() return this (Luigi Pinca) #35805
  • [b6b7a3b86a] - http: lazy create IncomingMessage.headers (Robert Nagy) #35281
  • [86ed87b6b7] - http2: fix reinjection check (Momtchil Momtchev) #35678
  • [5833007eb0] - http2: reinject data received before http2 is attached (Momtchil Momtchev) #35678
  • [cfe61b8714] - http2: remove unsupported %.* specifier (Momtchil Momtchev) #35694
  • [d2f574b5be] - lib: let abort_controller target be EventTarget (Daijiro Wachi) #35869
  • [b1e531a70b] - lib: use primordials when calling methods of Error (Antoine du Hamel) #35837
  • [0f5a8c55c2] - module: runtime deprecate subpath folder mappings (Guy Bedford) #35747
  • [d16e2fa69a] - n-api: napi_make_callback emit async init with resource of async_context (legendecas) #32930
  • [0c17dbd201] - n-api: revert change to finalization (Michael Dawson) #35777
  • [fb7196434e] - src: remove redundant OpenSSLBuffer (James M Snell) #35663
  • [c9225789d3] - src: remove ERR prefix in WebCryptoKeyExportStatus (Daniel Bevenius) #35639
  • [4128eefcb3] - src: remove ignore GCC -Wcast-function-type for v8 (Daniel Bevenius) #35768
  • [4b8b5fee6a] - src: use MaybeLocal.ToLocal instead of IsEmpty (Daniel Bevenius) #35716
  • [01d7c46776] - Revert "src: ignore GCC -Wcast-function-type for v8.h" (Daniel Bevenius) #35758
  • [2868f52a5c] - stream: fix regression on duplex end (Momtchil Momtchev) #35941
  • [70c41a830d] - stream: remove redundant context from comments (Yash Ladha) #35728
  • [88eb6191e4] - stream: fix duplicate logic in stream destroy (Yash Ladha) #35727
  • [a41e3ebc3a] - timers: correct explanation in comment (Turner Jabbour) #35437
  • [ee15142fef] - tls: allow reading data into a static buffer (Andrey Pechkurov) #35753
  • [102d7dfe02] - zlib: test BrotliCompress throws invalid arg value (raisinten) #35830

Documentation commits

Other commits