@percy/core 1.32.8-beta.1 → 1.32.8-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.js +21 -4
- package/dist/session.js +50 -3
- package/package.json +9 -9
package/dist/browser.js
CHANGED
|
@@ -9,7 +9,7 @@ import rimraf from 'rimraf';
|
|
|
9
9
|
import logger from '@percy/logger';
|
|
10
10
|
import install from './install.js';
|
|
11
11
|
import { MAX_CDP_PAYLOAD } from './network.js';
|
|
12
|
-
import Session from './session.js';
|
|
12
|
+
import Session, { cdpTimeout, cdpTimeoutMessage } from './session.js';
|
|
13
13
|
import Page from './page.js';
|
|
14
14
|
|
|
15
15
|
// Chrome features Percy disables for v143 new-headless asset discovery.
|
|
@@ -156,6 +156,7 @@ export class Browser extends EventEmitter {
|
|
|
156
156
|
// Reset state for fresh launch
|
|
157
157
|
this.readyState = null;
|
|
158
158
|
this._closed = null;
|
|
159
|
+
// close() above already cleared every pending callback and its deadline
|
|
159
160
|
this.#callbacks.clear();
|
|
160
161
|
this.sessions.clear();
|
|
161
162
|
|
|
@@ -202,6 +203,7 @@ export class Browser extends EventEmitter {
|
|
|
202
203
|
|
|
203
204
|
// reject any pending callbacks
|
|
204
205
|
for (let callback of this.#callbacks.values()) {
|
|
206
|
+
clearTimeout(callback.timer);
|
|
205
207
|
callback.reject(Object.assign(callback.error, {
|
|
206
208
|
message: `Protocol error (${callback.method}): Browser closed.`
|
|
207
209
|
}));
|
|
@@ -311,14 +313,28 @@ export class Browser extends EventEmitter {
|
|
|
311
313
|
params
|
|
312
314
|
}));
|
|
313
315
|
|
|
314
|
-
// will resolve or reject when a matching response is received
|
|
316
|
+
// will resolve or reject when a matching response is received, or when
|
|
317
|
+
// the deadline below expires because no response is ever coming. The
|
|
318
|
+
// browser process can go silent the same way a renderer can - target
|
|
319
|
+
// creation and attachment strand here otherwise, before any page exists.
|
|
315
320
|
return new Promise((resolve, reject) => {
|
|
316
|
-
|
|
321
|
+
let callback = {
|
|
317
322
|
error: new Error(),
|
|
318
323
|
resolve,
|
|
319
324
|
reject,
|
|
320
325
|
method
|
|
321
|
-
}
|
|
326
|
+
};
|
|
327
|
+
let timeout = cdpTimeout();
|
|
328
|
+
if (timeout > 0) {
|
|
329
|
+
callback.timer = setTimeout(() => {
|
|
330
|
+
this.#callbacks.delete(id);
|
|
331
|
+
this.log.debug(`Protocol timeout (${method}) after ${timeout}ms`);
|
|
332
|
+
reject(Object.assign(callback.error, {
|
|
333
|
+
message: cdpTimeoutMessage(method, timeout)
|
|
334
|
+
}));
|
|
335
|
+
}, timeout);
|
|
336
|
+
}
|
|
337
|
+
this.#callbacks.set(id, callback);
|
|
322
338
|
});
|
|
323
339
|
}
|
|
324
340
|
}
|
|
@@ -374,6 +390,7 @@ export class Browser extends EventEmitter {
|
|
|
374
390
|
// resolve or reject a pending promise created with #send()
|
|
375
391
|
let callback = this.#callbacks.get(data.id);
|
|
376
392
|
this.#callbacks.delete(data.id);
|
|
393
|
+
clearTimeout(callback.timer);
|
|
377
394
|
|
|
378
395
|
/* istanbul ignore next: races with page._handleMessage() */
|
|
379
396
|
if (data.error) {
|
package/dist/session.js
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
import EventEmitter from 'events';
|
|
2
2
|
import logger from '@percy/logger';
|
|
3
|
+
|
|
4
|
+
// Node-side ceiling on a single CDP round trip. Chrome does not always answer:
|
|
5
|
+
// a renderer that is frozen, starved of CPU, or swapped out keeps its target
|
|
6
|
+
// attached and simply never replies. In-page deadlines cannot rescue that case
|
|
7
|
+
// — their timers live in the very renderer that stopped running — so with no
|
|
8
|
+
// deadline here `send()` never settles and the whole CLI blocks forever with
|
|
9
|
+
// no error, no log and an unfinalized build. Reproducible by freezing the
|
|
10
|
+
// renderer (`Page.setWebLifecycleState`) or descheduling it (SIGSTOP), both of
|
|
11
|
+
// which a small, memory-pressured CI agent can do on its own.
|
|
12
|
+
export const DEFAULT_CDP_TIMEOUT = 120000;
|
|
13
|
+
|
|
14
|
+
// The longest wait a caller could legitimately be running *inside* the page,
|
|
15
|
+
// doubled. Keeps the deadline above those so raising one of them can never
|
|
16
|
+
// turn into a spurious protocol timeout.
|
|
17
|
+
function inPageCeiling() {
|
|
18
|
+
return Math.max(parseInt(process.env.PERCY_PAGE_LOAD_TIMEOUT, 10) || 0, parseInt(process.env.PERCY_STORY_RENDER_TIMEOUT, 10) || 0) * 2;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Resolved once per process, and memoized so a mid-run env change cannot make
|
|
22
|
+
// concurrent sessions disagree. `PERCY_CDP_TIMEOUT=0` disables the deadline.
|
|
23
|
+
export function cdpTimeout() {
|
|
24
|
+
if (Session.TIMEOUT !== undefined) return Session.TIMEOUT;
|
|
25
|
+
let configured = parseInt(process.env.PERCY_CDP_TIMEOUT, 10);
|
|
26
|
+
Session.TIMEOUT = Number.isNaN(configured) ? Math.max(DEFAULT_CDP_TIMEOUT, inPageCeiling()) : Math.max(0, configured);
|
|
27
|
+
return Session.TIMEOUT;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Shared by both CDP deadlines - the session-scoped one below and the
|
|
31
|
+
// browser-scoped one in browser.js.
|
|
32
|
+
export function cdpTimeoutMessage(method, timeout) {
|
|
33
|
+
return `Protocol error (${method}): Timed out after ${timeout}ms ` + 'waiting for a response from the browser. The browser stopped responding — a ' + 'renderer or browser process that is frozen, starved of CPU, or swapped out ' + 'never replies and never runs its own timers. Raise PERCY_CDP_TIMEOUT if this ' + 'command is legitimately slower than that, or set it to 0 to disable the deadline.';
|
|
34
|
+
}
|
|
3
35
|
export class Session extends EventEmitter {
|
|
36
|
+
static TIMEOUT = undefined;
|
|
4
37
|
#callbacks = new Map();
|
|
5
38
|
log = logger('core:session');
|
|
6
39
|
children = new Map();
|
|
@@ -45,14 +78,26 @@ export class Session extends EventEmitter {
|
|
|
45
78
|
params
|
|
46
79
|
});
|
|
47
80
|
|
|
48
|
-
// will resolve or reject when a matching response is received
|
|
81
|
+
// will resolve or reject when a matching response is received, or when the
|
|
82
|
+
// deadline below expires because no response is ever coming
|
|
49
83
|
return new Promise((resolve, reject) => {
|
|
50
|
-
|
|
84
|
+
let callback = {
|
|
51
85
|
error: new Error(),
|
|
52
86
|
resolve,
|
|
53
87
|
reject,
|
|
54
88
|
method
|
|
55
|
-
}
|
|
89
|
+
};
|
|
90
|
+
let timeout = cdpTimeout();
|
|
91
|
+
if (timeout > 0) {
|
|
92
|
+
callback.timer = setTimeout(() => {
|
|
93
|
+
this.#callbacks.delete(id);
|
|
94
|
+
this.log.debug(`Protocol timeout (${method}) after ${timeout}ms`);
|
|
95
|
+
reject(Object.assign(callback.error, {
|
|
96
|
+
message: cdpTimeoutMessage(method, timeout)
|
|
97
|
+
}));
|
|
98
|
+
}, timeout);
|
|
99
|
+
}
|
|
100
|
+
this.#callbacks.set(id, callback);
|
|
56
101
|
});
|
|
57
102
|
}
|
|
58
103
|
_handleMessage(data) {
|
|
@@ -60,6 +105,7 @@ export class Session extends EventEmitter {
|
|
|
60
105
|
// resolve or reject a pending promise created with #send()
|
|
61
106
|
let callback = this.#callbacks.get(data.id);
|
|
62
107
|
this.#callbacks.delete(data.id);
|
|
108
|
+
clearTimeout(callback.timer);
|
|
63
109
|
|
|
64
110
|
/* istanbul ignore next: races with browser._handleMessage() */
|
|
65
111
|
if (data.error) {
|
|
@@ -80,6 +126,7 @@ export class Session extends EventEmitter {
|
|
|
80
126
|
|
|
81
127
|
// reject any pending callbacks
|
|
82
128
|
for (let callback of this.#callbacks.values()) {
|
|
129
|
+
clearTimeout(callback.timer);
|
|
83
130
|
callback.reject(Object.assign(callback.error, {
|
|
84
131
|
message: `Protocol error (${callback.method}): ${this.closedReason}`
|
|
85
132
|
}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/core",
|
|
3
|
-
"version": "1.32.8-beta.
|
|
3
|
+
"version": "1.32.8-beta.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -46,12 +46,12 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@grpc/grpc-js": "^1.14.3",
|
|
48
48
|
"@grpc/proto-loader": "^0.8.0",
|
|
49
|
-
"@percy/client": "1.32.8-beta.
|
|
50
|
-
"@percy/config": "1.32.8-beta.
|
|
51
|
-
"@percy/dom": "1.32.8-beta.
|
|
52
|
-
"@percy/logger": "1.32.8-beta.
|
|
53
|
-
"@percy/monitoring": "1.32.8-beta.
|
|
54
|
-
"@percy/webdriver-utils": "1.32.8-beta.
|
|
49
|
+
"@percy/client": "1.32.8-beta.2",
|
|
50
|
+
"@percy/config": "1.32.8-beta.2",
|
|
51
|
+
"@percy/dom": "1.32.8-beta.2",
|
|
52
|
+
"@percy/logger": "1.32.8-beta.2",
|
|
53
|
+
"@percy/monitoring": "1.32.8-beta.2",
|
|
54
|
+
"@percy/webdriver-utils": "1.32.8-beta.2",
|
|
55
55
|
"adm-zip": "^0.6.0",
|
|
56
56
|
"busboy": "^1.6.0",
|
|
57
57
|
"content-disposition": "^0.5.4",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"yaml": "^2.4.1"
|
|
68
68
|
},
|
|
69
69
|
"optionalDependencies": {
|
|
70
|
-
"@percy/cli-doctor": "1.32.8-beta.
|
|
70
|
+
"@percy/cli-doctor": "1.32.8-beta.2"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "3886c115aa583e2c5af3b16643dd34c379415f5b"
|
|
73
73
|
}
|