Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot unlock file "/home/runner/.cache/mongodb-binaries/5.0.7.lock", because it is not locked by this process #366

Open
jgcmarins opened this issue Jul 25, 2022 · 5 comments

Comments

@jgcmarins
Copy link

We've been experiencing some random test failures with this library and GitHub Actions.
Not sure which is causing the issue, but here's the error:
Cannot unlock file "/home/runner/.cache/mongodb-binaries/5.0.7.lock", because it is not locked by this process
Screen Shot 2022-07-25 at 11 53 36

@EmanuelCampos
Copy link

@jgcmarins you solved this?

@jgcmarins
Copy link
Author

@EmanuelCampos not yet

@guilherme-gm
Copy link

I am experiencing the same issue, which I found very weird since I have been using this for months with no errors.

I tried following the mongdb-memory-server library and I think I may have found the culprit.

The only place this error may be throw is at:
https://github.com/nodkz/mongodb-memory-server/blob/master/packages/mongodb-memory-server-core/src/util/lockfile.ts#L273

default here could only mean lockedDifferent. If we look into checkLock function, the only place where this value is returned is at:
https://github.com/nodkz/mongodb-memory-server/blob/master/packages/mongodb-memory-server-core/src/util/lockfile.ts#L126

And isAlive returns true only when the PID in the file (I guess) is not the same of the running process:
https://github.com/nodkz/mongodb-memory-server/blob/master/packages/mongodb-memory-server-core/src/util/utils.ts#L163

Thus, I think whenever there are multiple process running, there is a chance for this to happen. I am not sure why this never happened for 5 months and is now happening a lot though...

I don't know if there is a way to fix without changing mongodb-memory-server, also I am not sure why it works like that.

I will attempt to make jest workers using threads instead of child process, as this hopefully will make all of them have the same PID, and hopefully I don't get errors again. I will try to update here in a few days.

@aboruchovas
Copy link

@guilherme-gm any update? i'm also struggling with this

@guilherme-gm
Copy link

guilherme-gm commented Jun 23, 2024

I've only made a few CI runs since then (~5, I think), but using 1 Child Process seems to work.

Using Worker Threads instead of Child Processes did not work. It spawned several instances of mongo memory server at the same time and it was a mess.

I changed back to Child Process and limited to 1 worker when running in CI. It didn't fail in the few runs I had after that and I didn't notice any major performance impact on my tests (I don't have THAT many tests, so a few extra seconds in CI was not a problem)

I think this makes sense, since having a single process spawning mongo servers, running tests and shutting it down will prevent a case where another process is using the lock. But I still think it is something that should be addressed (maybe on mongodb-memory-server and not on jest-mongodb... but I am not 100% sure).

I don't remember the config from the top of my head, but should be easy to find it in jest docs. I will try to update this message tomorrow once I have access to my code.

Edit:
This is the setting I am using:

maxWorkers: (process.env.CI === 'true' ? 1 : '50%'),

I chose to only limit in CI, since I don't have issues when running locally (so far)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants