cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.09k stars 3.19k forks source link

POST request drops body sporadically #30619

Open FelixWhitefield opened 1 week ago

FelixWhitefield commented 1 week ago

Current behavior

Currently I have a POST request which sometimes drops its body, as when checking with the server it is making the request to the body is empty and the Content-Length is 0. This happens rarely, potentially 1 in 20 times when running the test locally and on our CI pipeline.

The POST request comes from the site I am trying to test, and is triggered when a button is clicked on a page. It should have a JSON body.

When running Cypress open with the developer tools open and looking at the request in the network tab, the request has the correct body. But when debugging the server, the request has no body.

I have turned on Cypress Debug logging and have found that when the request body is dropped, Cypress seems to create a proxied socket for the request. But when the request body gets to the server, this does not happen.

Logs (relating to the failed request) Failure Logs - When the request body is dropped (No response from the server because it is being debugged and was stopped when the issue occurred):

cypress:server:remote-states getting remote state: { auth: null, origin: 'https://our-server', strategy: 'http', fileServer: null, domainName: 'our-server', props: { port: '443', protocol: 'https:', subdomain: null, domain: '', tld: 'our-server' } } for: https://our-server/web_url/api/w/d/p/e+47ms
...
cypress:network:agent addRequest called { isHttps: true, href: 'https://our-server/web_url/api/w/d/p/e' } +49ms
cypress:network:agent got family { family: undefined, href: 'https://our-server/web_url/api/w/d/p/e' } +0ms
cypress:network:agent Creating proxied socket for https://our-server/web_url/api/w/d/p/e through http://127.0.0.1:64253 +0ms
...
cypress:network:agent Proxy socket for https://our-server/web_url/api/w/d/p/e established +1ms

Success Logs - When the request body makes it to the server:

cypress:server:remote-states getting remote state: { auth: null, origin: 'https://our_server', strategy: 'http', fileServer: null, domainName: 'our_server', props: { port: '443', protocol: 'https:', subdomain: null, domain: '', tld: 'our_server' } } for: https://our-server/web_url/api/w/d/p/e +54ms
...
cypress:network:agent addRequest called { isHttps: true, href: 'https://our-server/web_url/api/w/d/p/e' } +49ms
cypress:network:agent got family { family: undefined, href: 'https://our-server/web_url/api/w/d/p/e' } +0ms
...
cypress:net-stubbing:server:intercept-response InterceptResponse { req: { url: '/web_url/api/w/d/p/e' }, request: undefined } +84ms
...
POST /web_url/api/w/d/p/e 200 842.990 ms - -

We do have cypress-ntlm-auth installed, as we use NTLM for our authentication - in case it could be that plugin causing the issue.

I am happy to provide more debug logging if the above does not suffice.

Desired behavior

Cypress should pass the request body through all the time

Test code to reproduce

I cannot reliable recreate the issue

Cypress Version

13.15.0

Node version

v20.11.1 on CI, v18.20.0 locally

Operating System

Windows 22631.4317 locally

Debug Logs

No response

Other

No response

ryanthemanuel commented 1 day ago

The proxied socket that you point out will only be created if the HTTPS_PROXY environment variable is set and the url that you're dealing successfully is honored by the logic in this dependency. Is it possible that there is a difference in how/what environment variables are set between the success and failure scenarios?

FelixWhitefield commented 23 hours ago

Thank you for your reply.

The environment variables should be the same between the success and failure scenarios as they happen within the same cypress open session. I retry the test locally by clicking the retry button in the Cypress app.

When running the tests I am connected to a corporate VPN as the server hosting the site is in our corporate network and is not accessible otherwise. Could that be a factor into the issue?