Skip to content

Commit 5a4e339

Browse files
authored
fix(server): increase timeout when making Marionette connection (#7372)
1 parent 18f127f commit 5a4e339

File tree

10 files changed

+134
-102
lines changed

10 files changed

+134
-102
lines changed

packages/server/__snapshots__/5_cdp_spec.ts.js

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,3 @@
1-
exports['e2e cdp / fails when remote debugging port cannot be connected to'] = `
2-
3-
====================================================================================================
4-
5-
(Run Starting)
6-
7-
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
8-
│ Cypress: 1.2.3 │
9-
│ Browser: FooBrowser 88 │
10-
│ Specs: 1 found (spec.ts) │
11-
│ Searched: cypress/integration/spec.ts │
12-
└────────────────────────────────────────────────────────────────────────────────────────────────┘
13-
14-
15-
────────────────────────────────────────────────────────────────────────────────────────────────────
16-
17-
Running: spec.ts (1 of 1)
18-
Failed to connect to Chrome, retrying in 1 second (attempt 18/32)
19-
Failed to connect to Chrome, retrying in 1 second (attempt 19/32)
20-
Failed to connect to Chrome, retrying in 1 second (attempt 20/32)
21-
Failed to connect to Chrome, retrying in 1 second (attempt 21/32)
22-
Failed to connect to Chrome, retrying in 1 second (attempt 22/32)
23-
Failed to connect to Chrome, retrying in 1 second (attempt 23/32)
24-
Failed to connect to Chrome, retrying in 1 second (attempt 24/32)
25-
Failed to connect to Chrome, retrying in 1 second (attempt 25/32)
26-
Failed to connect to Chrome, retrying in 1 second (attempt 26/32)
27-
Failed to connect to Chrome, retrying in 1 second (attempt 27/32)
28-
Failed to connect to Chrome, retrying in 1 second (attempt 28/32)
29-
Failed to connect to Chrome, retrying in 1 second (attempt 29/32)
30-
Failed to connect to Chrome, retrying in 1 second (attempt 30/32)
31-
Failed to connect to Chrome, retrying in 1 second (attempt 31/32)
32-
Failed to connect to Chrome, retrying in 1 second (attempt 32/32)
33-
Cypress failed to make a connection to the Chrome DevTools Protocol after retrying for 20 seconds.
34-
35-
This usually indicates there was a problem opening the Chrome browser.
36-
37-
The CDP port requested was 7777.
38-
39-
Error details:
40-
41-
Error: connect ECONNREFUSED 127.0.0.1:7777
42-
[stack trace lines]
43-
44-
45-
`
46-
471
exports['e2e cdp / handles disconnections as expected'] = `
482
493
====================================================================================================

packages/server/__snapshots__/protocol_spec.ts.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
exports['lib/browsers/protocol ._getDelayMsForRetry retries as expected for up to 20 seconds 1'] = [
1+
exports['lib/browsers/protocol ._getDelayMsForRetry retries as expected for up to 50 seconds 1'] = [
22
100,
33
100,
44
100,
@@ -31,5 +31,35 @@ exports['lib/browsers/protocol ._getDelayMsForRetry retries as expected for up t
3131
1000,
3232
1000,
3333
1000,
34+
1000,
35+
1000,
36+
1000,
37+
1000,
38+
1000,
39+
1000,
40+
1000,
41+
1000,
42+
1000,
43+
1000,
44+
1000,
45+
1000,
46+
1000,
47+
1000,
48+
1000,
49+
1000,
50+
1000,
51+
1000,
52+
1000,
53+
1000,
54+
1000,
55+
1000,
56+
1000,
57+
1000,
58+
1000,
59+
1000,
60+
1000,
61+
1000,
62+
1000,
63+
1000,
3464
1000
3565
]

packages/server/lib/browsers/chrome.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import appData from '../util/app_data'
1010
import fs from '../util/fs'
1111
import { CdpAutomation } from './cdp_automation'
1212
import * as CriClient from './cri-client'
13-
import protocol from './protocol'
13+
import * as protocol from './protocol'
1414
import utils from './utils'
1515
import { Browser } from './types'
1616

packages/server/lib/browsers/firefox-util.ts

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Marionette from 'marionette-client'
55
import { Command } from 'marionette-client/lib/marionette/message.js'
66
import util from 'util'
77
import Foxdriver from '@benmalka/foxdriver'
8-
import protocol from './protocol'
8+
import * as protocol from './protocol'
99

1010
const errors = require('../errors')
1111

@@ -23,6 +23,22 @@ const getTabId = (tab) => {
2323
return _.get(tab, 'browsingContextID')
2424
}
2525

26+
const getDelayMsForRetry = (i) => {
27+
if (i < 10) {
28+
return 100
29+
}
30+
31+
if (i < 18) {
32+
return 500
33+
}
34+
35+
if (i < 63) {
36+
return 1000
37+
}
38+
39+
return
40+
}
41+
2642
const getPrimaryTab = Bluebird.method((browser) => {
2743
const setPrimaryTab = () => {
2844
return browser.listTabs()
@@ -154,21 +170,7 @@ export default {
154170
await protocol._connectAsync({
155171
host: '127.0.0.1',
156172
port,
157-
getDelayMsForRetry: (i) => {
158-
if (i < 10) {
159-
return 100
160-
}
161-
162-
if (i < 18) {
163-
return 500
164-
}
165-
166-
if (i < 33) {
167-
return 1000
168-
}
169-
170-
return
171-
},
173+
getDelayMsForRetry,
172174
})
173175

174176
const foxdriver = await Foxdriver.attach('127.0.0.1', port)
@@ -220,7 +222,16 @@ export default {
220222
},
221223

222224
async setupMarionette (extensions, url, port) {
223-
const driver = new Marionette.Drivers.Promises({ port })
225+
await protocol._connectAsync({
226+
host: '127.0.0.1',
227+
port,
228+
getDelayMsForRetry,
229+
})
230+
231+
const driver = new Marionette.Drivers.Promises({
232+
port,
233+
tries: 1, // marionette-client has its own retry logic which we want to avoid
234+
})
224235

225236
const sendMarionette = (data) => {
226237
return driver.send(new Command(data))

packages/server/lib/browsers/firefox.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import urlUtil from 'url'
88
import FirefoxProfile from 'firefox-profile'
99
import firefoxUtil from './firefox-util'
1010
import utils from './utils'
11+
import * as launcherDebug from '@packages/launcher/lib/log'
1112
import { Browser } from './types'
13+
const errors = require('../errors')
1214

1315
const debug = Debug('cypress:server:browsers:firefox')
1416

@@ -281,6 +283,8 @@ const defaultPreferences = {
281283
// allow getUserMedia APIs on insecure domains
282284
'media.devices.insecure.enabled': true,
283285
'media.getusermedia.insecure.enabled': true,
286+
287+
'marionette.log.level': launcherDebug.log.enabled ? 'Debug' : undefined,
284288
}
285289

286290
export async function open (browser: Browser, url, options: any = {}) {
@@ -411,6 +415,9 @@ export async function open (browser: Browser, url, options: any = {}) {
411415
const browserInstance = await utils.launch(browser, 'about:blank', launchOptions.args)
412416

413417
await firefoxUtil.setup({ extensions: launchOptions.extensions, url, foxdriverPort, marionettePort })
418+
.catch((err) => {
419+
errors.throw('FIREFOX_COULD_NOT_CONNECT', err)
420+
})
414421

415422
return browserInstance
416423
}

packages/server/lib/browsers/protocol.js renamed to packages/server/lib/browsers/protocol.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
const _ = require('lodash')
2-
const CRI = require('chrome-remote-interface')
3-
const { connect } = require('@packages/network')
1+
import _ from 'lodash'
2+
import CRI from 'chrome-remote-interface'
3+
import { connect } from '@packages/network'
4+
import Bluebird from 'bluebird'
5+
import la from 'lazy-ass'
6+
import Debug from 'debug'
7+
import { Socket } from 'net'
48
const errors = require('../errors')
5-
const Promise = require('bluebird')
6-
const la = require('lazy-ass')
79
const is = require('check-more-types')
8-
const debug = require('debug')('cypress:server:protocol')
910

10-
function _getDelayMsForRetry (i) {
11+
const debug = Debug('cypress:server:browsers:protocol')
12+
13+
export function _getDelayMsForRetry (i) {
1114
if (i < 10) {
1215
return 100
1316
}
@@ -16,20 +19,22 @@ function _getDelayMsForRetry (i) {
1619
return 500
1720
}
1821

19-
if (i < 33) { // after 5 seconds, begin logging and retrying
22+
if (i < 63) { // after 5 seconds, begin logging and retrying
2023
errors.warning('CDP_RETRYING_CONNECTION', i)
2124

2225
return 1000
2326
}
27+
28+
return
2429
}
2530

26-
function _connectAsync (opts) {
27-
return Promise.fromCallback((cb) => {
31+
export function _connectAsync (opts) {
32+
return Bluebird.fromCallback((cb) => {
2833
connect.createRetryingSocket(opts, cb)
2934
})
3035
.then((sock) => {
3136
// can be closed, just needed to test the connection
32-
sock.end()
37+
(sock as Socket).end()
3338
})
3439
}
3540

@@ -72,7 +77,7 @@ const findStartPageTarget = (connectOpts) => {
7277
* Waits for the port to respond with connection to Chrome Remote Interface
7378
* @param {number} port Port number to connect to
7479
*/
75-
const getWsTargetFor = (port) => {
80+
export const getWsTargetFor = (port) => {
7681
debug('Getting WS connection to CRI on port %d', port)
7782
la(is.port(port), 'expected port number', port)
7883

@@ -106,7 +111,7 @@ const getWsTargetFor = (port) => {
106111
throw err
107112
}
108113

109-
return Promise.delay(delay)
114+
return Bluebird.delay(delay)
110115
.then(retry)
111116
})
112117
}
@@ -118,9 +123,3 @@ const getWsTargetFor = (port) => {
118123
errors.throw('CDP_COULD_NOT_CONNECT', port, err)
119124
})
120125
}
121-
122-
module.exports = {
123-
_connectAsync,
124-
_getDelayMsForRetry,
125-
getWsTargetFor,
126-
}

packages/server/lib/errors.coffee

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ getMsgByType = (type, arg1 = {}, arg2, arg3) ->
884884
"""
885885
when "CDP_COULD_NOT_CONNECT"
886886
"""
887-
Cypress failed to make a connection to the Chrome DevTools Protocol after retrying for 20 seconds.
887+
Cypress failed to make a connection to the Chrome DevTools Protocol after retrying for 50 seconds.
888888
889889
This usually indicates there was a problem opening the Chrome browser.
890890
@@ -894,6 +894,16 @@ getMsgByType = (type, arg1 = {}, arg2, arg3) ->
894894
895895
#{arg2.stack}
896896
"""
897+
when "FIREFOX_COULD_NOT_CONNECT"
898+
"""
899+
Cypress failed to make a connection to Firefox.
900+
901+
This usually indicates there was a problem opening the Firefox browser.
902+
903+
Error details:
904+
905+
#{arg1.stack}
906+
"""
897907
when "CDP_COULD_NOT_RECONNECT"
898908
"""
899909
There was an error reconnecting to the Chrome DevTools protocol. Please restart the browser.
@@ -902,7 +912,7 @@ getMsgByType = (type, arg1 = {}, arg2, arg3) ->
902912
"""
903913
when "CDP_RETRYING_CONNECTION"
904914
"""
905-
Failed to connect to Chrome, retrying in 1 second (attempt #{chalk.yellow(arg1)}/32)
915+
Failed to connect to Chrome, retrying in 1 second (attempt #{chalk.yellow(arg1)}/62)
906916
"""
907917
when "DEPRECATED_BEFORE_BROWSER_LAUNCH_ARGS"
908918
"""

packages/server/test/e2e/5_cdp_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ describe('e2e cdp', function () {
1717
restoreEnv()
1818
})
1919

20-
e2e.it('fails when remote debugging port cannot be connected to', {
20+
// NOTE: this test takes almost a minute and is largely redundant with protocol_spec
21+
e2e.it.skip('fails when remote debugging port cannot be connected to', {
2122
project: Fixtures.projectPath('remote-debugging-port-removed'),
2223
spec: 'spec.ts',
2324
browser: 'chrome',
2425
expectedExitCode: 1,
25-
snapshot: true,
2626
})
2727

2828
// https://github.com/cypress-io/cypress/issues/5685

0 commit comments

Comments
 (0)