Multiple zombie processes when running Cypress inside the Docker with Node
See original GitHub issueCurrent behavior
When running Cypress tests in an infinite loop inside a docker container and starting the test script with node cypress.js
, we can see a huge amount of zombie (<defunct>
) processes.
When starting the same cypress-test.js file inside the docker container by using a shell script - all child processes are killed correctly, so no zombies are left.
Due to this bug, it is impossible to run cypress tests using ‘pm2’ or ‘node’ inside a docker container. At one point all processes just stop, because no free PID is left, so no new process can be started.
Tested with Cypress Version: 7.7.0, 9.6.1
Desired behavior
No <defunct> zombie processes should appear, when running cypress tests synchronously inside a docker container by using ENTRYPOINT [ "node", "./cypress-test.js" ]
Test code to reproduce
Dockerfile:
FROM cypress/browsers:node14.16.0-chrome90-ff88
RUN mkdir /opt/prj/
WORKDIR /opt/prj/
COPY package.json package-lock.json *node_modules /opt/prj/
RUN npm install
RUN $(npm bin)/cypress verify
COPY . /opt/prj/
ENTRYPOINT [ "node", "./cypress-test.js" ]
cypress-test.js:
const cypress = require('cypress');
const TEST_FOLDER_PATH = process.cwd() + '/cypress/integration/test/';
(async () => {
while (true) {
const result = await cypress.run({
spec: TEST_FOLDER_PATH + 'test.spec.js',
video: false
});
}
})();
/cypress/integration/test/test.spec.js
describe('Test', () => {
it('should be true', () => {
expect(1).to.equal(1);
});
});
cypress.json
{
"pluginsFile": "cypress/plugins/index.js",
"retries": {
"runMode": 1,
"openMode": 0
},
"defaultCommandTimeout": 15000,
"video": false,
"videoCompression": false,
"videoUploadOnPasses": false,
"viewportWidth": 1280,
"viewportHeight": 720
}
Start docker:
> docker build . -t cypress
> docker run cypress
Look up the name of the running docker container and execute:
> docker exec -it <container_name> bash
> ps aux
___________________ EXAMPLE WITH NO ZOMBIES____________________________________________ When replacing the ENTRYPOINT in the Dockerfile with:
RUN ["chmod", "+x", "/opt/prj/commands.sh"]
ENTRYPOINT [ "./commands.sh" ]
commands.sh
#!/bin/bash
node cypress-tests.js
NO Zombies
Cypress Version
7.7.0, 9.6.1
Other
No response
Issue Analytics
- State:
- Created a year ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
@daria-graf - I stand corrected, you are absolutely right now that I look back at this. I wasn’t reading your sample script correctly, and thought it was leaving the zombies
Cypress
processes itself, which is not the case.With that said, I’m not sure this is going to be easy to prioritize for the team. I’m reopening, but doubt we’ll have time to take a look - if you or another contributor wants to take a crack at auditing how we open processes and properly waiting for them, feel free to ping me on a PR and I’ll take a look.
–init / tini remains at least a valid workaround though.
Based on the article you included, it seems we may have two solutions: