-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Pipe to self: "Error: Lock file is already being hold" #1835
Comments
The switch to using `yargs-promise` for `ipfs init` and `ipfs daemon` commands caused an unhandled promise rejection and in some cases would cause an error to not be printed to the console. This PR greatly simplifies the code in `src/cli/bin.js`, to always use `yargs-promise`. Command handlers are now passed an async `getIpfs` function instead of an `ipfs` instance. It means that we don't have to differentiate between commands that use an IPFS instance in `src/cli/bin.js`, giving the handler the power to call `getIpfs` or not to obtain an IPFS instance as and when needed. This removes a whole bunch of complexity from `src/cli/bin.js` at the cost of adding a single line to every command handler that needs to use an IPFS instance. This enables operations like `echo "hello" | jsipfs add -q | jsipfs cid base32` to work without `jsipfs cid base32` failing because it's trying to acquire a repo lock when it doesn't use IPFS at all. fixes #1835 refs #1858 refs libp2p/js-libp2p#311 License: MIT Signed-off-by: Alan Shaw <[email protected]>
The switch to using `yargs-promise` for `ipfs init` and `ipfs daemon` commands caused an unhandled promise rejection and in some cases would cause an error to not be printed to the console. This PR greatly simplifies the code in `src/cli/bin.js`, to always use `yargs-promise`. Command handlers are now passed an async `getIpfs` function instead of an `ipfs` instance. It means that we don't have to differentiate between commands that use an IPFS instance in `src/cli/bin.js`, giving the handler the power to call `getIpfs` or not to obtain an IPFS instance as and when needed. This removes a whole bunch of complexity from `src/cli/bin.js` at the cost of adding a single line to every command handler that needs to use an IPFS instance. This enables operations like `echo "hello" | jsipfs add -q | jsipfs cid base32` to work without `jsipfs cid base32` failing because it's trying to acquire a repo lock when it doesn't use IPFS at all. fixes #1835 refs #1858 refs libp2p/js-libp2p#311 License: MIT Signed-off-by: Alan Shaw <[email protected]>
The switch to using `yargs-promise` for `ipfs init` and `ipfs daemon` commands caused an unhandled promise rejection and in some cases would cause an error to not be printed to the console. This PR greatly simplifies the code in `src/cli/bin.js`, to always use `yargs-promise`. Command handlers are now passed an async `getIpfs` function instead of an `ipfs` instance. It means that we don't have to differentiate between commands that use an IPFS instance in `src/cli/bin.js`, giving the handler the power to call `getIpfs` or not to obtain an IPFS instance as and when needed. This removes a whole bunch of complexity from `src/cli/bin.js` at the cost of adding a single line to every command handler that needs to use an IPFS instance. This enables operations like `echo "hello" | jsipfs add -q | jsipfs cid base32` to work without `jsipfs cid base32` failing because it's trying to acquire a repo lock when it doesn't use IPFS at all. fixes #1835 refs #1858 refs libp2p/js-libp2p#311 License: MIT Signed-off-by: Alan Shaw <[email protected]>
@alanshaw unfortunately still getting this issue, with this node program:
The error is being caught in the
Running this program several times in a row (one after another, not simultaneously) will cause the error to happen. If I stop, wait a bit, and run it again, it sometimes works. Seems like it could be related to #229. How can i help? |
Same problem here. During the development, it is imperative that the app will be restarted with code modifications frequently, which leads to the "Lock file is already being hold" error frequently. Previous instance holding the lock is fine, but how to override / release it in new instance ? Is there anything we can do in the code to resolve this situation and force the node to This may turnout to be a problem in production also, if this file-system lock thing cannot be resolved programatically. |
You could remove the |
I also frequently get this when running unit tests that create an instance and then fail for whatever reason. When I run the tests again this will almost always happen. I also handle it by manually deleting the repo.lock folder. |
Only one IPFS node can access an IPFS repo at a time. Use the In tests you should use a temporary directory that you clean up after the node has shutdown. You could also use https://github.com/ipfs/js-ipfsd-ctl to make this job easier. |
Only 1 is running at a time. It starts, it crashes, and then it doesn't start again. I've resolved it by deleting the repo.lock file in code. But it's pretty confusing. |
If you retry after 10s I think a PR to |
It happens most often with tests, but it also sometimes happens when the app I'm testing crashes. I'll look into the temp repo for the tests. The 10s thing is helpful info and makes sense because I'm usually able to restart it if I wait a bit. |
I came here because of the problem in my js, the problem was that I called IPFS.create() two times (in two different places), and so I guess they somehow conflicted. Solved it by initializing it in one place. Hope it might help people like me :) |
@ungarson thanks for your post. This solved the problem for me. I built an api and every time I call a specific route, I was calling const IPFS = require('ipfs-core')
async function initGlobalIPFS() {
global.IPFS = await IPFS.create()
};
initGlobalIPFS() This works, however, I'm not clear on why this works. Does anyone have any reference documentation that I can read through to get a better understanding of what is happening when calling the |
@bn185068 please can you ask on https://discuss.ipfs.io ? You're more likely to get a better answer there, this repo is for reporting bugs/issues with js-ipfs and not asking how-do-I type questions. |
@achingbrain apologies. I assumed since I'm reporting that I also experienced this "LockExistsError" error while using this package, that it was appropriate to report how I solved it on the thread where others are experiencing the same error. Didn't realize I couldn't ask a question about the code that I'm using in an issue attached to that code's repo. I'll ask my question about the js-ipfs code on the ipfs discussion forum. Thanks for the reference link. |
jsipfs cid base32
fails to start because repo is locked byjsipfs add -q
I think go-ipfs has the concept of command requirements, perhaps we need something similar i.e.
jsipfs cid
does not require a repo so shouldn't need to obtain a lock.The text was updated successfully, but these errors were encountered: