cypress: Error running proxy middleware: Cannot call this.next() more than once in the same middleware function.

Current behavior

We run our Cypress component tests on CI (this issue is not reproducible when running locally).

Every test run fails every time with the following errors (one at a time), with the first two being most common.

Unfortunately we could not track specific test case as it’s failing on random tests.

As far as I understand those are from the http proxy implementation (we use cy.intercept in every test case).

The merged PR https://github.com/cypress-io/cypress/pull/25702 was suppose to add some additional logging details to this error, however it did not change anything for us. Still the same error message, without any details about which particular command is causing it.

I’ve tried running it with DEBUG=cypress:*, increasing stack-trace-limit, etc, but there was nothing that could give any idea of the reason.

Error running proxy middleware: Cannot call this.next() more than once in the same middleware function. Doing so can cause unintended issues.
Error: Error running proxy middleware: Cannot call this.next() more than once in the same middleware function. Doing so can cause unintended issues.
    at p.next (<embedded>:4515:179166)
    at e.continueResponse (<embedded>:4311:112116)
    at e.onResponse (<embedded>:4311:112012)
    at D (<embedded>:4311:97448)
    at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async d.handleSubscriptions (<embedded>:4311:101367)
    at async Object.f (<embedded>:4311:110738)
onResponse cannot be called twice
Error: onResponse cannot be called twice
    at onResponse (<embedded>:4363:98636)
    at D (<embedded>:4363:96927)
    at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async d.handleSubscriptions (<embedded>:4363:100846)
    at async Object.f (<embedded>:4363:110217)
Cannot read properties of undefined (reading 'testsuite')
TypeError: Cannot read properties of undefined (reading 'testsuite')
    at n (<embedded>:2861:19018)
    at E.<anonymous> (<embedded>:2861:19631)
    at R.emit (node:events:539:35)
    at S.emit (<embedded>:4592:16654)
    at Object.onMocha (<embedded>:4639:425416)
    at p.<anonymous> (<embedded>:4639:66799)
    at p.emit (node:events:527:28)
    at p.emitUntyped (<embedded>:4350:84346)
    at <embedded>:4350:91863
    at process.processTicksAndRejections (node:internal/process/task_queues:78:11)
Cannot read properties of undefined (reading 'length')
TypeError: Cannot read properties of undefined (reading 'length')
    at D (<embedded>:2861:18626)
    at E._onSuiteEnd (<embedded>:2861:19429)
    at E.<anonymous> (<embedded>:2861:19568)
    at R.emit (node:events:527:28)
    at S.emit (<embedded>:4592:16654)
    at Object.onMocha (<embedded>:4639:425416)
    at p.<anonymous> (<embedded>:4639:66799)
    at p.emit (node:events:527:28)
    at p.emitUntyped (<embedded>:4350:84346)
    at <embedded>:4350:91863
    at process.processTicksAndRejections (node:internal/process/task_queues:78:11)

Desired behavior

Cypress should not throw these errors.

Cypress should include larger stack trace and include a reason of failure in error logs.

Test code to reproduce

Unfortunately I don’t have the code that reproduces it, as it only happens on our CI pipeline. It happens for random tests (we have hundreds of them). We cannot reproduce locally.

Cypress Version

12.6.0

Node version

16.19.0

Operating System

gitlab runner/docker

Debug Logs

cypress:net-stubbing:server:intercept-request request/response finished, cleaning up { requestId: 'interceptedRequest2435' } +100ms
  cypress:net-stubbing:server:util sending event to driver { eventName: 'after:response', data: { eventId: 'event2440', subscription: { eventName: 'after:response', await: false, routeId: '1676623707106-1564' }, browserRequestId: '3633.379', requestId: 'interceptedRequest2435', data: {} } } +93ms
  cypress:net-stubbing:server:util sending event to driver { eventName: 'after:response', data: { eventId: 'event2441', subscription: { eventName: 'after:response', await: false, routeId: '1676623705855-1449' }, browserRequestId: '3633.379', requestId: 'interceptedRequest2435', data: {} } } +1ms
  cypress:net-stubbing:server:util sending event to driver { eventName: 'after:response', data: { eventId: 'event2442', subscription: { eventName: 'after:response', await: false, routeId: '1676623705763-1424' }, browserRequestId: '3633.379', requestId: 'interceptedRequest2435', data: {} } } +0ms
  cypress:server:util:socket_allowed allowed socket closed, removing { localPort: 34592 } +188ms
  cypress:server:util:socket_allowed allowed socket closed, removing { localPort: 34580 } +1ms
  cypress:server:socket-base backend:request { eventName: 'net', args: [ 'event:handler:resolved', { eventId: 'event2417', headers: [Object], body: '......', method: null, httpVersion: null, statusCode: 200, statusMessage: null } ] } +54ms
  cypress:net-stubbing:server:driver-events received driver event { eventName: 'event:handler:resolved', args: [ 'event:handler:resolved', { eventId: 'event2417', headers: [Object], body: '......', method: null, httpVersion: null, statusCode: 200, statusMessage: null } ] } +54ms
Error running proxy middleware: Detected `this.next()` was called more than once in the same middleware function, but a middleware can only be completed once.
Error: Error running proxy middleware: Detected `this.next()` was called more than once in the same middleware function, but a middleware can only be completed once.
    at f.next (<embedded>:5146:265746)
    at e.continueResponse (<embedded>:4942:117690)
    at Object.b (<embedded>:4942:118691)
    at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
  cypress:server:lib:util:suppress_warnings suppressed emitWarning from node: { process: process { version: 'v16.16.0', versions: { node: '16.16.0', v8: '10.6.194.11-electron.0', uv: '1.43.0', zlib: '1.2.12.1-motley', brotli: '1.0.9', ares: '1.18.1', modules: '109', nghttp2: '1.47.0', napi: '8', llhttp: '6.0.7', openssl: '1.1.1', cldr: '41.0', icu: '71.1', tz: '2022b', unicode: '14.0', electron: '21.0.0', chrome: '106.0.5249.51' }, arch: 'x64', platform: 'linux', release: { name: 'node', lts: 'Gallium', sourceUrl: 'https://nodejs.org/download/release/v16.16.0/node-v16.16.0.tar.gz', headersUrl: 'https://nodejs.org/download/release/v16.16.0/node-v16.16.0-headers.tar.gz' }, _rawDebug: [Function: _rawDebug], moduleLoadList: [ 'Internal Binding native_module', 'Internal Binding errors', 'NativeModule internal/errors', 'Internal Binding config',... 131 more items ], binding:

Other

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

@matys84pl - A new build with additional logs is available here: https://github.com/cypress-io/cypress/commit/38b560f69f066a4b14a3a2203bfcb7ed30930c21#commitcomment-101682422. If you can reproduce the issue with DEBUG logs again using that build, it should help me track down what’s going on here.