pact-foundation / pact-js

JS version of Pact. Pact is a contract testing framework for HTTP APIs and non-HTTP asynchronous messaging systems.
https://pact.io
Other
1.63k stars 348 forks source link

node sometimes hangs when NODE_V8_COVERAGE is set #1074

Open jhayes-dev opened 1 year ago

jhayes-dev commented 1 year ago

Software versions

Issue Checklist

Please confirm the following:

Expected behavior

Node should not hang when generating coverage data while using pact.

Actual behavior

Depending on how many tests I run, node hangs when writing the coverage data.

Steps to reproduce

See the attached zip file, test-pact-hang.zip, with a docker-compose.yml and Dockerfile that reproduce the problem. When you run docker compose up --build node hangs using 100% CPU and 7.2GB RAM. Node does not hang when NODE_V8_COVERAGE is not set in the docker-compose file. Uncommenting global.gc(); in test-pact.js prevents the hang when NODE_V8_COVERAGE is set.

Relevant log files

See logs.txt in the zip file.

mefellows commented 1 year ago

Thanks for this, one guess would be something to do with how we use native libraries using the N-API. I'd have to look up if there are practices required to make it work.

Did you get into any analysis as to where the hang is happening? Does it happen outside of docker also?

Also I'm assuming you can run the same instrumentation on a non-Pact project and it works as expected?

jhayes-dev commented 1 year ago

I uncovered the hang on our Jenkins server running Amazon Linux 2. The tests run fine on macOS with NODE_V8_COVERAGE set.

At first I thought it could be linux+limited RAM problem because top showed node using 11GBs of RAM on Jenkins. I tried it in docker because I could easily limit resources allocated to the process and I could test it on my Mac.

This project defines 6 consumer interaction and 3 other tests. The hang does not manifest when only running the Pact interactions. We get valid coverage data when running the non-Pact tests. The tests define the Pact object even when the Pact tests are skipped if that maters.

I was surprised I had iterate 100 times to get it to hang in the test script.

mhofman commented 1 year ago

FYI we ran into the same issue with Ava. I worked around it by patching ava to call v8.takeCoverage() before its worker exits.

YOU54F commented 5 months ago

i believe a fix had landed in node 20 that will resolve this and was backported to node 18

thanks @mhofman for tracking.

https://github.com/nodejs/node/pull/51290#issuecomment-1881137494