cypress: Cypress Error Socket Hang Up on NodeJS requests.
Current behavior:
When importing a nodeJS library or file that uses request, when we attempt to do a request we are getting:
socket hang up
at connResetException (internal/errors.js:559:14)
at TLSSocket.socketOnEnd (_http_client.js:433:23)
at TLSSocket.emit (events.js:208:15)
at endReadableNT (_stream_readable.js:1168:12)
at processTicksAndRejections (internal/process/task_queues.js:77:11) {
code: 'ECONNRESET',
When running this same file via node test.js it runs successfully.
Desired behavior:
It should work the same way when node executes the file and when Cypress calls the file.
Test code to reproduce
In Plugins > index.js
var api = require('api-helper.js');
module.exports = (on, config) => {
on('task', {
test: async () => {
const result = await api.testEndpoint();
console.log('Result is: ', result);
}
});
return config;
};
Plugins > api-helper.js
var request = require('request');
class ApiHelper {
constructor() {}
testEndpoint(){
return request.get("http://ourApiEndpoint.com/somethinghere/something");
}
}
var test = new ApiHelper();
test.testEndpoint();
Now if we run this api-helper.js file using node in the cli like:
node api-helper.js
It runs successfully, when it’s called through cypress we receive the following error:
Error: socket hang up
at connResetException (internal/errors.js:559:14)
at TLSSocket.socketOnEnd (_http_client.js:433:23)
at TLSSocket.emit (events.js:208:15)
at endReadableNT (_stream_readable.js:1168:12)
at processTicksAndRejections (internal/process/task_queues.js:77:11)
Couple of disclaimers and clarifications.
- We are not not using
cy.requestbecause we need to do certain request sending a certificate pfx file which is not supported curently. - We are obviously not running the code as stated above to execute as soon as it starts, this is just to demonstrate the error.
Versions
Windows 10 Cypress 4.0.2 Electron 78
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 1
- Comments: 23 (6 by maintainers)
I figured out that the container that the request is sent to, runs out of memory and I’ve increased the memory size of Docker and this is resolved.