Skip to content

Commit

Permalink
Merge branch 'nodejs:main' into test-runner-hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow authored Jul 10, 2022
2 parents 3b62025 + a933a75 commit 2b4fba6
Show file tree
Hide file tree
Showing 42 changed files with 816 additions and 217 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
!.github
!.gitignore
!.gitkeep
!.gitpod.yml
!.mailmap
!.nycrc
!.yamllint.yaml
Expand Down
9 changes: 9 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Ref: https://github.com/gitpod-io/gitpod/issues/6283#issuecomment-1001043454
tasks:
- init: ./configure && timeout 50m make -j16 || true

# Ref: https://www.gitpod.io/docs/prebuilds#github-specific-configuration
github:
prebuilds:
# add a "Review in Gitpod" button as a comment to pull requests (defaults to true)
addComment: false
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ Saúl Ibarra Corretgé <[email protected]> <[email protected]>
Scott Blomquist <[email protected]> <[email protected]>
Segu Riluvan <[email protected]> <[email protected]>
Sergey Kryzhanovsky <[email protected]> <[email protected]>
Sergey Petushkov <[email protected]> <[email protected]>
Sergey Zelenov <[email protected]> <[email protected]>
Shannen Saez <[email protected]>
Shaopeng Zhang <[email protected]>
Expand Down
9 changes: 8 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -3465,7 +3465,7 @@ Meek Simbule <[email protected]>
Michael Ficarra <[email protected]>
hiroki osame <[email protected]>
Eugene Chapko <[email protected]>
Sergey Petushkov <sergey.petushkov@protonmail.com>
Sergey Petushkov <petushkov.sergey@gmail.com>
Caleb Everett <[email protected]>
JialuZhang-intel <[email protected]>
Moshe Atlow <[email protected]>
Expand All @@ -3474,5 +3474,12 @@ James Scott-Brown <[email protected]>
supriyo-biswas <[email protected]>
Giacomo Gregoletto <[email protected]>
italo jose <[email protected]>
Kazuma Ohashi <[email protected]>
Douglas Wilson <[email protected]>
0xSanyam <[email protected]>
Alena Khineika <[email protected]>
Basit <[email protected]>
Kid <[email protected]>
Jeremy Rose <[email protected]>

# Generated by tools/update-authors.mjs
14 changes: 8 additions & 6 deletions benchmark/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,16 @@ function formatResult(data) {
}

function sendResult(data) {
if (process.send && Object.hasOwn(process.env, 'NODE_RUN_BENCHMARK_FN')) {
if (process.send) {
// If forked, report by process send
process.send(data, () => {
// If, for any reason, the process is unable to self close within
// a second after completing, forcefully close it.
setTimeout(() => {
process.exit(0);
}, 5000).unref();
if (Object.hasOwn(process.env, 'NODE_RUN_BENCHMARK_FN')) {
// If, for any reason, the process is unable to self close within
// a second after completing, forcefully close it.
setTimeout(() => {
process.exit(0);
}, 5000).unref();
}
});
} else {
// Otherwise report by stdout
Expand Down
15 changes: 15 additions & 0 deletions deps/corepack/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## [0.12.0](https://github.com/nodejs/corepack/compare/v0.11.2...v0.12.0) (2022-07-09)


### Features

* add support for hash checking ([#133](https://github.com/nodejs/corepack/issues/133)) ([6a480a7](https://github.com/nodejs/corepack/commit/6a480a72c2e9fc6725f2ab6dfaf4c52e4d3d2ade))
* add support for tags and ranges in `prepare` command ([#136](https://github.com/nodejs/corepack/issues/136)) ([29da06c](https://github.com/nodejs/corepack/commit/29da06c515e917829e5ffbedb34284a6597e9d56))
* update package manager versions ([#129](https://github.com/nodejs/corepack/issues/129)) ([2470f58](https://github.com/nodejs/corepack/commit/2470f58b74491a1301221df643c55be5adf1d349))
* update package manager versions ([#139](https://github.com/nodejs/corepack/issues/139)) ([cd0dcad](https://github.com/nodejs/corepack/commit/cd0dcade85621199048d7ca30dfc3efce11e1f37))


### Bug Fixes

* streamline the cache exploration ([#135](https://github.com/nodejs/corepack/issues/135)) ([185da44](https://github.com/nodejs/corepack/commit/185da44078fd1ca34aec2e4e6f8a52ecffcf3c11))

## [0.11.2](https://github.com/nodejs/corepack/compare/v0.11.1...v0.11.2) (2022-06-13)

### Bug Fixes
Expand Down
163 changes: 102 additions & 61 deletions deps/corepack/dist/corepack.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion deps/corepack/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "corepack",
"version": "0.11.2",
"version": "0.12.0",
"homepage": "https://github.com/nodejs/corepack#readme",
"bugs": {
"url": "https://github.com/nodejs/corepack/issues"
Expand Down
35 changes: 35 additions & 0 deletions doc/api/diagnostics_channel.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,41 @@ channel.subscribe(onMessage);
channel.unsubscribe(onMessage);
```

### Built-in Channels

#### HTTP

`http.client.request.start`

* `request` {http.ClientRequest}

Emitted when client starts a request.

`http.client.response.finish`

* `request` {http.ClientRequest}
* `response` {http.IncomingMessage}

Emitted when client receives a response.

`http.server.request.start`

* `request` {http.IncomingMessage}
* `response` {http.ServerResponse}
* `socket` {net.Socket}
* `server` {http.Server}

Emitted when server receives a request.

`http.server.response.finish`

* `request` {http.IncomingMessage}
* `response` {http.ServerResponse}
* `socket` {net.Socket}
* `server` {http.Server}

Emitted when server sends a response.

[`'uncaughtException'`]: process.md#event-uncaughtexception
[`channel.subscribe(onMessage)`]: #channelsubscribeonmessage
[`diagnostics_channel.channel(name)`]: #diagnostics_channelchannelname
17 changes: 17 additions & 0 deletions doc/api/net.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,23 @@ added: v0.1.90

Emitted when the server has been bound after calling [`server.listen()`][].

### Event: `'drop'`

<!-- YAML
added: REPLACEME
-->

When the number of connections reaches the threshold of `server.maxConnections`,
the server will drop new connections and emit `'drop'` event instead. If it is a
TCP server, the argument is as follows, otherwise the argument is `undefined`.

* `data` {Object} The argument passed to event listener.
* `localAddress` {string} Local address.
* `localPort` {number} Local port.
* `remoteAddress` {string} Remote address.
* `remotePort` {number} Remote port.
* `remoteFamily` {string} Remote IP family. `'IPv4'` or `'IPv6'`.

### `server.address()`

<!-- YAML
Expand Down
1 change: 0 additions & 1 deletion doc/contributing/diagnostic-tooling-support-tiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ The tools are currently assigned to Tiers as follows:

| Tool Type | Tool/API Name | Regular Testing in Node.js CI | Integrated with Node.js | Target Tier |
| --------- | ------------------------- | ----------------------------- | ----------------------- | ----------- |
| FFDC | node-report | No | No | 1 |
| Memory | V8 heap profiler | No | Yes | 1 |
| Memory | V8 sampling heap profiler | No | Yes | 1 |
| AsyncFlow | Async Hooks (API) | ? | Yes | 1 |
Expand Down
15 changes: 15 additions & 0 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ const {

const kClientRequestStatistics = Symbol('ClientRequestStatistics');

const dc = require('diagnostics_channel');
const onClientRequestStartChannel = dc.channel('http.client.request.start');
const onClientResponseFinishChannel = dc.channel('http.client.response.finish');

const { addAbortSignal, finished } = require('stream');

let debug = require('internal/util/debuglog').debuglog('http', (fn) => {
Expand Down Expand Up @@ -367,6 +371,11 @@ ClientRequest.prototype._finish = function _finish() {
},
});
}
if (onClientRequestStartChannel.hasSubscribers) {
onClientRequestStartChannel.publish({
request: this,
});
}
};

ClientRequest.prototype._implicitHeader = function _implicitHeader() {
Expand Down Expand Up @@ -645,6 +654,12 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
},
});
}
if (onClientResponseFinishChannel.hasSubscribers) {
onClientResponseFinishChannel.publish({
request: req,
response: res,
});
}
req.res = res;
res.req = req;

Expand Down
10 changes: 10 additions & 0 deletions lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ assertCrypto();

const {
ERR_CRYPTO_FIPS_FORCED,
ERR_WORKER_UNSUPPORTED_OPERATION,
} = require('internal/errors').codes;
const constants = internalBinding('constants').crypto;
const { getOptionValue } = require('internal/options');
Expand Down Expand Up @@ -127,6 +128,12 @@ function lazyWebCrypto() {
return webcrypto;
}

let ownsProcessState;
function lazyOwnsProcessState() {
ownsProcessState ??= require('internal/worker').ownsProcessState;
return ownsProcessState;
}

// These helper functions are needed because the constructors can
// use new, in which case V8 cannot inline the recursive constructor call
function createHash(algorithm, options) {
Expand Down Expand Up @@ -250,6 +257,9 @@ function setFips(val) {
if (val) return;
throw new ERR_CRYPTO_FIPS_FORCED();
} else {
if (!lazyOwnsProcessState()) {
throw new ERR_WORKER_UNSUPPORTED_OPERATION('Calling crypto.setFips()');
}
setFipsCrypto(val);
}
}
Expand Down
36 changes: 6 additions & 30 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
'use strict';

const {
ArrayPrototypeIndexOf,
ArrayPrototypeJoin,
ArrayPrototypeShift,
ArrayPrototypeSlice,
Expand All @@ -33,7 +32,6 @@ const {
ErrorCaptureStackTrace,
FunctionPrototypeBind,
FunctionPrototypeCall,
MathMin,
NumberIsNaN,
ObjectCreate,
ObjectDefineProperty,
Expand All @@ -55,7 +53,10 @@ const kRejection = SymbolFor('nodejs.rejection');

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

const { inspect } = require('internal/util/inspect');
const {
inspect,
identicalSequenceRange,
} = require('internal/util/inspect');

let spliceOne;

Expand Down Expand Up @@ -424,31 +425,6 @@ EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
return _getMaxListeners(this);
};

// Returns the length and line number of the first sequence of `a` that fully
// appears in `b` with a length of at least 4.
function identicalSequenceRange(a, b) {
for (let i = 0; i < a.length - 3; i++) {
// Find the first entry of b that matches the current entry of a.
const pos = ArrayPrototypeIndexOf(b, a[i]);
if (pos !== -1) {
const rest = b.length - pos;
if (rest > 3) {
let len = 1;
const maxLen = MathMin(a.length - i, rest);
// Count the number of consecutive entries.
while (maxLen > len && a[i + len] === b[pos + len]) {
len++;
}
if (len > 3) {
return [len, i];
}
}
}
}

return [0, 0];
}

function enhanceStackTrace(err, own) {
let ctorInfo = '';
try {
Expand All @@ -465,9 +441,9 @@ function enhanceStackTrace(err, own) {
const ownStack = ArrayPrototypeSlice(
StringPrototypeSplit(own.stack, '\n'), 1);

const { 0: len, 1: off } = identicalSequenceRange(ownStack, errStack);
const { len, offset } = identicalSequenceRange(ownStack, errStack);
if (len > 0) {
ArrayPrototypeSplice(ownStack, off + 1, len - 2,
ArrayPrototypeSplice(ownStack, offset + 1, len - 2,
' [... lines matching original stack trace ...]');
}

Expand Down
10 changes: 7 additions & 3 deletions lib/internal/cluster/round_robin_handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const { constants } = internalBinding('tcp_wrap');

module.exports = RoundRobinHandle;

function RoundRobinHandle(key, address, { port, fd, flags, backlog }) {
function RoundRobinHandle(key, address, { port, fd, flags, backlog, readableAll, writableAll }) {
this.key = key;
this.all = new SafeMap();
this.free = new SafeMap();
Expand All @@ -34,8 +34,12 @@ function RoundRobinHandle(key, address, { port, fd, flags, backlog }) {
backlog,
});
} else
this.server.listen(address, backlog); // UNIX socket path.

this.server.listen({
path: address,
backlog,
readableAll,
writableAll,
}); // UNIX socket path.
this.server.once('listening', () => {
this.handle = this.server._handle;
this.handle.onconnection = (err, handle) => this.distribute(err, handle);
Expand Down
27 changes: 24 additions & 3 deletions lib/internal/modules/esm/fetch_module.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,28 @@ function createUnzip() {
return createUnzip();
}

/**
* Redirection status code as per section 6.4 of RFC 7231:
* https://datatracker.ietf.org/doc/html/rfc7231#section-6.4
* and RFC 7238:
* https://datatracker.ietf.org/doc/html/rfc7238
* @param {number} statusCode
* @returns {boolean}
*/
function isRedirect(statusCode) {
switch (statusCode) {
case 300: // Multiple Choices
case 301: // Moved Permanently
case 302: // Found
case 303: // See Other
case 307: // Temporary Redirect
case 308: // Permanent Redirect
return true;
default:
return false;
}
}

/**
* @param {URL} parsed
* @returns {Promise<CacheEntry> | CacheEntry}
Expand All @@ -107,9 +129,8 @@ function fetchWithRedirects(parsed) {
// `finally` on network error/timeout.
const { 0: res } = await once(req, 'response');
try {
const isRedirect = res.statusCode >= 300 && res.statusCode <= 303;
const hasLocation = ObjectPrototypeHasOwnProperty(res.headers, 'location');
if (isRedirect && hasLocation) {
if (isRedirect(res.statusCode) && hasLocation) {
const location = new URL(res.headers.location, parsed);
if (location.protocol !== 'http:' && location.protocol !== 'https:') {
throw new ERR_NETWORK_IMPORT_DISALLOWED(
Expand All @@ -127,7 +148,7 @@ function fetchWithRedirects(parsed) {
err.message = `Cannot find module '${parsed.href}', HTTP 404`;
throw err;
}
if (res.statusCode > 303 || res.statusCode < 200) {
if (res.statusCode < 200 || res.statusCode >= 400) {
throw new ERR_NETWORK_IMPORT_DISALLOWED(
res.headers.location,
parsed.href,
Expand Down
Loading

0 comments on commit 2b4fba6

Please sign in to comment.