-
Notifications
You must be signed in to change notification settings - Fork 1.2k
daemon leaves behind api file lock on error #229
Comments
(@whyrusleeping can confirm) go-ipfs checks if the daemon is indeed on and if it doesn't find anything on the port left behind, it just deletes the lock and spawns the daemon. |
great, so the work is
|
exactly :) |
@noffle would you like to handle this one? :) |
Sorry David, I don't have the bandwidth right now for this. Feel free to
reassign.
|
@victorbjelkholm does this look like something you can take on? :) Thank you |
Just checked the go code, and we are actually not doing what go does at all. In go the api file is deleted on closing, but does not stop the daemon from starting up. Rather it is simply overwritten. For locking the repo to a single daemon a file called |
It looks like the best bet for doing this is using
and using those for |
Why can't we not remove the lock file on crash/close? And the only thing the daemon has to check, is if the file is there or not. |
@victorbjelkholm it gets removed on |
Does not work, as it misses the actual important syscall config we need :( I found https://crates.io/crates/fs2 which is supposed to work on windows as well as on nix systems so I'm looking into creating a small wrapper around it for js. |
@diasdavid by leveraging domain/cluster, which is basically what they are meant for. We can isolate the main process and listen for shutdowns/exists and clean up properly. |
This does not help at all with things like power loss. Also it's a massive overhead of running two v8 processes just for simple monitoring purposes. |
@victorbjelkholm also, Domains and Cluster are modules that historically have been a source of issues in Node.js land, so much that they were considered to be removed from core several times. And even with that, it would not save us from problems that are beyond the OS level (machine being shutdown, kernel panic, etc). Checking the API file and testing if the API is running is also how go-ipfs does it //cc @whyrusleeping |
@diasdavid not entirely see my comment for what actually happens in go: #229 (comment) |
@dignifiedquire go does:
//cc @whyrusleeping |
yes but the locking of the repo has nothing to do with the api file. It purely happens through repo.lock as described above |
ah yes, there are two files, one for the lock, one for the api (where it is listening), the process that owns the API should also own the lock. |
@victorbjelkholm There is a reason why Unix has its own lock function/syscall. If you lock using the dedicated subroutine the lock will be released automatically when process exits, thus preventing stale lock. Locking by creating file with PID, as done quite frequently, has been proven error full because of PID reuse. It might happen that process crashes, its PID is reused and the lock is considered valid.
|
I finally found a solution to do |
@dignifiedquire this will only work when used with |
@diasdavid do we need this anywhere else? This is only related to the http-api/cli as far as I understand |
That is indeed correct :) |
As a note, this has been solved :) |
\o/
|
While using the
During the development, the app is being restarted with code modifications, which leads to the above error frequently. Previous instance holding the lock is fine, but how to override / release it in new instance ? |
Having this problem when trying to integrate with Next.js while in dev mode. Adding the error to help others find
|
I'm also having this problem when using
|
@andykitt this usually happens when another IPFS process is running or the previous process did not exit cleanly - is either of these the case for you? |
Has anyone written a wrapper for the IPFS command line that just calls |
This worked for me: const node = await IPFS.create(ipfsConfig)
const stop = () => {
node.stop()
process.exit()
}
process.on("SIGTERM", stop)
process.on("SIGINT", stop)
process.on("SIGHUP", stop)
process.on("uncaughtException", stop)
|
@AlexMesser |
@achingbrain yes, first I tried it with UPD: my bad, added const node = await IPFS.create(ipfsConfig)
const stop = async () => {
try {
await node.stop()
} catch (e) {
console.log(e.message)
}
process.exit()
}
process.on("SIGTERM", stop)
process.on("SIGINT", stop)
process.on("SIGHUP", stop)
process.on("uncaughtException", stop) However it works. Lock file will be deleted anyway. |
this not worked for Still i have LockExistsError: Lock already being held for file |
When the daemon hits an error on load like #228, it will leave around the
~/.ipfs/api
file lock.go-ipfs
seems to be smart about detecting this and cleaning it up, but it will inhibit future invocations of thejs-ipfs
daemon.The text was updated successfully, but these errors were encountered: