Skip to content

[WasmFS] Make OPFS error handling more robust and regular#17774

Merged
tlively merged 4 commits intomainfrom
wasmfs-opfs-errors-refactor
Sep 1, 2022
Merged

[WasmFS] Make OPFS error handling more robust and regular#17774
tlively merged 4 commits intomainfrom
wasmfs-opfs-errors-refactor

Conversation

@tlively
Copy link
Member

@tlively tlively commented Sep 1, 2022

Refactor the existing error handling in the OPFS backend according to these
principles:

  1. Determine error codes where errors occur. This simplifies the code by
    eliminating ad hoc magic error constants and improves the code by making
    errors more specific.

  2. Return errors in existing return channels where possible, rather than adding
    new out-params for errors. This reduces code size and makes the code more
    robust by reducing the space of meaningless return values.

  3. Do not allow any exceptions to escape. Unknown exceptions are reported to
    the console and converted to catch-all EIO error codes. Exceptions escaping
    the async OFPS code cause deadlocks, so they must be rigorously avoided.

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.

Great!

[&](auto ctx) { _wasmfs_opfs_open_blob(ctx.ctx, fileID, &id); });
if (id < 0) {
return -EACCES;
return -id;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return -id;
return id;

Copy link
Member Author

Choose a reason for hiding this comment

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

Oof, good catch.

// TODO: This is the correct error code for negative read positions, but we
// should handle other errors correctly as well.
return nread < 0 ? -EINVAL : nread;
return nread;
Copy link
Member

Choose a reason for hiding this comment

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

I guess this means we can only read/write 2GB at a time? I suppose that's ok...

Copy link
Member Author

Choose a reason for hiding this comment

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

In wasm32 the read syscalls can only read 2GB at a time anyway because their result type is a 32-bit ssize_t. We should update this to use the full 63 bits in wasm64, though. I think there's a TODO for that.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, thanks. Doesn't sound urgent anyhow I guess, 31 bit reads is quite a lot...

Base automatically changed from wasmfs-read-write-errors to main September 1, 2022 18:45
Refactor the existing error handling in the OPFS backend according to these
principles:

 1. Determine error codes where errors occur. This simplifies the code by
    eliminating ad hoc magic error constants and improves the code by making
    errors more specific.

 2. Return errors in existing return channels where possible, rather than adding
    new out-params for errors. This reduces code size and makes the code more
    robust by reducing the space of meaningless return values.

 3. Do not allow any exceptions to escape. Unknown exceptions are reported to
    the console and converted to catch-all EIO error codes. Exceptions escaping
    the async OFPS code cause deadlocks, so they must be rigorously avoided.
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.

2 participants