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

c-api: Expose async_stack_size configuration #6762

Closed
wants to merge 1 commit into from

Conversation

guregu
Copy link
Contributor

@guregu guregu commented Jul 24, 2023

Adds wasm_config_async_stack_size_set to C API. Also updates the stack-related comments in config.h to match the latest Rust ones.

Motivation: I want to set the stack size in wasmtime-go, but max_wasm_stack is limited by async_stack_size, so we need to set this too.

@guregu guregu requested a review from a team as a code owner July 24, 2023 17:57
@guregu guregu requested review from itsrainy and removed request for a team July 24, 2023 17:57
@github-actions github-actions bot added the wasmtime:c-api Issues pertaining to the C API. label Jul 24, 2023
@github-actions
Copy link

Subscribe to Label Action

cc @peterhuene

This issue or pull request has been labeled: "wasmtime:c-api"

Thus the following users have been cc'd because of the following labels:

  • peterhuene: wasmtime:c-api

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@alexcrichton
Copy link
Member

Thanks! Can you elaborate a bit more on how this is used though? Async isn't exposed through the C API so in theory this configuration option shouldn't do anything in the C API, but if it's causing issues then that's a bug where when async is turned off it shouldn't be consulted.

@guregu
Copy link
Contributor Author

guregu commented Jul 24, 2023

@alexcrichton I agree that's it's more likely a bug (or maybe misconfiguration?) somewhere else.

Basically, if I try to set the stack size to 8MB in wasmtime-go it will fail with this message:

thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: max_wasm_stack size cannot exceed the async_stack_size', crates/c-api/src/engine.rs:33:38
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5
SIGABRT: abort
PC=0x198cf4724 m=0 sigcode=0
signal arrived during cgo execution

So I figured exposing this knob could work around that. But perhaps the issue lies elsewhere 🤔

Would be happy to move this to wasmtime-go issue if that is the case!

@guregu
Copy link
Contributor Author

guregu commented Jul 24, 2023

@alexcrichton I made an issue here for the wasmtime-go problem: bytecodealliance/wasmtime-go#182. Please feel free to close this if it's not needed after all!

@alexcrichton
Copy link
Member

Oh no you're all good, I think that this is still a bug in Wasmtime, so this is the right place to fix it. I don't think there's a way to work around that from wasmtime-go right now.

I think the fix though is to update this condition to additionally check async_support because if that's disabled then there's no need to test anything about the async stack size, which I think would fix your use case because async_support is false for the C API.

@guregu
Copy link
Contributor Author

guregu commented Jul 24, 2023

Aha, that makes sense! I will take that approach in a new PR. Thank you for the help 🙏

@jameysharp
Copy link
Contributor

I think that's a good fix to apply. In addition it occurs to me that perhaps the C API should build the wasmtime crate with the async feature disabled, since it can't make use of the async support anyway. That would have avoided this bug because the if statement in question wouldn't have been compiled in at all.

guregu added a commit to guregu/wasmtime that referenced this pull request Jul 25, 2023
Fixes an issue where max_wasm_stack was being validated against
async_stack_size when async_support was disabled, discussed in bytecodealliance#6762.
@guregu
Copy link
Contributor Author

guregu commented Jul 25, 2023

New PR that takes the suggested approach: #6771

@guregu guregu closed this Jul 25, 2023
github-merge-queue bot pushed a commit that referenced this pull request Jul 25, 2023
Fixes an issue where max_wasm_stack was being validated against
async_stack_size when async_support was disabled, discussed in #6762.
@guregu guregu deleted the async-stack-size-capi branch August 1, 2023 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasmtime:c-api Issues pertaining to the C API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants