Skip to content

GH-49995: [R][Wasm] Fix threading issue under Wasm/Emscripten#49996

Open
amoeba wants to merge 3 commits into
apache:mainfrom
amoeba:GH-49995--r-wasm-threading
Open

GH-49995: [R][Wasm] Fix threading issue under Wasm/Emscripten#49996
amoeba wants to merge 3 commits into
apache:mainfrom
amoeba:GH-49995--r-wasm-threading

Conversation

@amoeba
Copy link
Copy Markdown
Member

@amoeba amoeba commented May 19, 2026

Rationale for this change

#49982 added a basic Wasm build but after doing some testing I ran into an issue with threading.

What changes are included in this PR?

  • The main fix: Modified CanRunWithCapturedR so it's always false under Emscripten. This change is the only change that was strictly needed to fix my issue. I'm not a pro with this part of the codebase so scrutiny welcome.
  • I also set options(arrow.use_threads = FALSE) when running under Wasm just in case since it makes sense to not use threads in a Wasm context

Are these changes tested?

Yes. Crossbow jobs show the build works and I have a demo at https://amoeba.github.io/arrow-r-wasm/.

Are there any user-facing changes?

No.

@amoeba
Copy link
Copy Markdown
Member Author

amoeba commented May 19, 2026

@github-actions crossbow submit test-r-wasm

@github-actions
Copy link
Copy Markdown

Revision: dadf0f5

Submitted crossbow builds: ursacomputing/crossbow @ actions-9b0263bfa9

Task Status
test-r-wasm GitHub Actions

@amoeba
Copy link
Copy Markdown
Member Author

amoeba commented May 19, 2026

@github-actions crossbow submit test-r-wasm

@amoeba
Copy link
Copy Markdown
Member Author

amoeba commented May 19, 2026

With dadf0f5, Parquet reading works with my local test. I'm testing the changes separately so I know what's actually fixing things here.

@github-actions
Copy link
Copy Markdown

Revision: abaacb8

Submitted crossbow builds: ursacomputing/crossbow @ actions-510511a107

Task Status
test-r-wasm GitHub Actions

@amoeba amoeba marked this pull request as ready for review May 20, 2026 03:56
@amoeba amoeba requested review from jonkeane and thisisnic as code owners May 20, 2026 03:56
@amoeba
Copy link
Copy Markdown
Member Author

amoeba commented May 20, 2026

I marked this as ready for review. The PR description hopefully explains all that's needed and I put together a demo at https://amoeba.github.io/arrow-r-wasm/

@amoeba amoeba changed the title GH-49995: [R][Wasm] Fix threading issue under Wasm/Emscritpen GH-49995: [R][Wasm] Fix threading issue under Wasm/Emscripten May 20, 2026
Comment on lines +48 to +56
bool CanRunWithCapturedR() {
#ifdef __EMSCRIPTEN__
// Threading is not supported under Emscripten/WASM. Always take the
// synchronous path to avoid attempting pthread_create which will fail
// with "thread constructor failed: Not supported".
return false;
#else
return MainRThread::GetInstance().Executor() == nullptr;
#endif
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it possible to add a test (or maybe it's that we actually need to run the tests under wasm(???) to catch this?

@github-actions github-actions Bot added awaiting changes Awaiting changes and removed awaiting review Awaiting review labels May 20, 2026
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 this pull request may close these issues.

2 participants