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

Fixes PROXYFS error check #18716

Merged
merged 3 commits into from
Feb 16, 2023
Merged

Fixes PROXYFS error check #18716

merged 3 commits into from
Feb 16, 2023

Conversation

iliakan
Copy link
Contributor

@iliakan iliakan commented Feb 11, 2023

Make the check work reliably cross-FS.

Fixes #18715

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good to me with one minor comment.

src/library_fs.js Show resolved Hide resolved
@@ -1061,7 +1061,7 @@ function wrapSyscallFunction(x, library, isWasi) {
pre += 'try {\n';
handler +=
"} catch (e) {\n" +
" if (typeof FS == 'undefined' || !(e instanceof FS.ErrnoError)) throw e;\n";
" if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;\n";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we maybe need to think a little more carefully about this. I think maybe the arguments made in #16994 (comment) may apply here.

If we do want to make this code work between 2 different emscripten instances I think we should have some testing of that mode, and also make sure that doesn't effect the code size for folks who don't need/want that.

Copy link
Contributor Author

@iliakan iliakan Feb 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of test helps to detect errors passed between iframes too. Not sure if it's needed here, though ;)

That's a JS trick like 20 years old. Or more, didn't count. Since the moment instanceof appeared, I'd guess =)

A theoretical downside is that inheritance tests won't work, unlike instanceof, but we don't inherit from FS.ErrnoError. So that's fine.

Also, no one meddles with FS errors by assigning them a custom name, so guess won't be any compat issues.

PROXYFS without the proper test (as I suggest or give your idea) is rather buggy, it causes failures in all wrapped syscalls. It almost feels like I'm beta-testing this feature =)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @sbc100 that a test would be good for this. Otherwise I think this makes sense to do for the reasons you said @iliakan - instanceof is just brittle in JS, unfortunately (due to iframes etc.).

Copy link
Contributor Author

@iliakan iliakan Feb 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @sbc100 that a test would be good for this. Otherwise I think this makes sense to do for the reasons you said @iliakan - instanceof is just brittle in JS, unfortunately (due to iframes etc.).

Do I need to write an FS test that fails without my PR, but succeeds with it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually not sure about this patch at all. If you are trying to import/use the FS object from another module why wouldn't you also import its FS.ErrnoError? In that mode wouldn't you want to completely avoid declaring FS (or FS.ErrnoError) in the consumer module?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i.e. if you want module to somehow share and FS then only one of them should declare the FS, right?

Copy link
Contributor Author

@iliakan iliakan Feb 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added/pushed the test that demonstrates the bug on the current HEAD, and it's fixed in my branch.

In short, the problem happens in access syscall to an absent path in the mounted FS, it calls lookupPath and expects it to return an FS.ErrnoError, and it is such error, but from another FS, so the failing instanceof check causes a swift death.

P.S. So this happens in the "normal" scenario of PROXYFS usage, no magic.

P.P.S. Thank you for fast consideration of the PR. I almost forgot what the issue was exactly, but easily managed to remember and write it out.

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this is needed for the existing PROXYFS filesystem.

test/test_other.py Outdated Show resolved Hide resolved
@sbc100
Copy link
Collaborator

sbc100 commented Feb 14, 2023

@kripken I think you need to accept these changes before we can land.

@iliakan iliakan changed the title fixes #18715 Fixes PROXYFS error check Feb 15, 2023
@kripken kripken merged commit e64e370 into emscripten-core:main Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PROXYFS bug (with a fix)
3 participants