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

Callback swallowed leading to Mutex unlock error #221

Open
1j01 opened this issue Mar 30, 2018 · 6 comments
Open

Callback swallowed leading to Mutex unlock error #221

1j01 opened this issue Mar 30, 2018 · 6 comments
Labels

Comments

@1j01
Copy link
Contributor

1j01 commented Mar 30, 2018

Whew! This took some debugging.

I got Uncaught Error: unlock of a non-locked mutex, and at first I thought it was the readdir failing (and it kind of is), then I noticed that I had typo'd "file" instead of another variable, and I was trying to hunt down where that variable came from, assuming it was some sort of getter that was causing the error, but it turned out that any error in my callback would cause the mutex error.
So I continued debugging, and here's what I found:

  • It's swallowing errors when it should check for ENOENT, in OverlayFS's readdir, here (unrelatedly it should probably also check for ENOENT here)
  • It's wrapping my callback in XmlHttpRequest.prototype.readdir, and then
  • It's calling my callback twice! the second time to handle the error from the first callback!

public readdir(path: string, cb: BFSCallback<string[]>): void {
try {
cb(null, this.readdirSync(path));
} catch (e) {
cb(e);
}
}

The combined result of this is that swallows any errors in my callback, and gives that mutex error instead of any reasonable error.

I'll send a PR for this.

@jvilk
Copy link
Owner

jvilk commented Mar 30, 2018

Good catch! I should do an audit of the codebase, looking for potential re-applications of callbacks.

Is the OverlayFS issue that stat is swallowing an error code that it should return?

The stat code is doing a mkdir -p to find the parent directory that exists before creating all needed subdirectories; what error code is it swallowing that you'd expect it to return?

Similarly, readdir may operate on directories that only exist in writable, so errors from readable.readdir are expected. Is there a particular error code it's swallowing that it should return instead? Note that this code may also receive a ENOTDIR error if readable contains a file that was later deleted, so it's a bit more subtle than just checking for ENOENT.

@jvilk jvilk added the bug label Mar 30, 2018
@1j01
Copy link
Contributor Author

1j01 commented Mar 30, 2018

Is the OverlayFS issue that stat is swallowing an error code that it should return?

I don't think the statDone one affected me, I was only using readdir (I haven't created any directories yet)

what error code is it swallowing that you'd expect it to return?

Possibly EPERM, or an unexpected type of error like ended up getting passed to the callback in readdir (which should be an ApiError) this._readable.readdir(p, (err: ApiError, rFiles: string[]) => {
But I guess maybe not.

The main thing was the double callback. I'll send a PR for that at least. And the callback being part of a try block at all.

I should do an audit of the codebase, looking for potential re-applications of callbacks.

I've started doing this audit now, and there sure are a lot of cases, but I'm on a roll. 😄

@jvilk
Copy link
Owner

jvilk commented Mar 30, 2018

Ignoring EPERM should be fine; it could be a directory that you didn't have permission to, a chmod caused it to move to writable (because you updated the directory/file), and now you do have access to it. Keep in mind readable is a read-only snapshot of some file system, and writable stores the changes. Data in readable may be out-of-sync with reality.

@1j01
Copy link
Contributor Author

1j01 commented Mar 30, 2018

Yeah, that makes sense.

@dr-vortex
Copy link
Collaborator

@1j01 What is the status of this issue? I've made a ton of improvements to BFS in recent months so this issue may not be relevant or present anymore.

Repository owner locked and limited conversation to collaborators Oct 25, 2023
@dr-vortex
Copy link
Collaborator

@dr-vortex dr-vortex closed this as not planned Won't fix, can't repro, duplicate, stale Oct 25, 2023
Repository owner unlocked this conversation May 17, 2024
@dr-vortex dr-vortex reopened this May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants