Rust codegen: Function::new lacks Send + Sync bounds for closures invoked and dropped across Valdi threads
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 73/100
Research direction
Start in valdi_core/src/valdi_core/rust/function.rs and read Function::new and its invoke trampoline, then check nearby tests for function construction or thread-safety bounds. Update the closure bounds as described and run the relevant Rust tests. Done when closures must satisfy Send + Sync at both entry points and the tests pass.
Written by the indexing model from the issue text.
Description
Found while reviewing https://github.com/Snapchat/Valdi/pull/211 (native Rust code generation). Not blocking that PR.
Function::new lacks Send + Sync bounds for closures invoked and dropped across Valdi threads
File: valdi_core/src/valdi_core/rust/function.rs
When a closure capturing !Send or !Sync state (such as Rc or RefCell) is passed to Function::new and exposed to the Valdi JS runtime, invoking or dropping it from the JS or GC thread causes a data race and undefined behavior. Function::new only constrains F: Fn(ValdiCall) -> Result<(), String> + 'static, omitting Send + Sync.
valdi_rust_value_new_function wraps the closure in a ref-counted RustValueFunction (Valdi::ValueFunction) that Valdi can invoke from the JS thread and destroy from whichever thread drops the last reference. Without Send + Sync bounds on F, Rust's type system cannot prevent non-thread-safe captures from crossing threads through C++.
Require F: Fn(ValdiCall) -> Result<(), String> + Send + Sync + 'static on Function::new and its invoke trampoline.
- Dominant language
- C++
- Stars
- 16.4k
- Forks
- 539
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Snapchat/Valdi
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 1 day
-
Rust codegen: RustMethodResolver fails to unwrap .nullable on optional interface/module methodsOpen
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
deepseek-ai/DeepGEMM-Ascend#49 ·
Maintainers usually reply within 1 day
-
bug needs testing platform:windows topic:buildsystem topic:platforms
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
godotengine/godot#126110 · 1 comment ·
Maintainers usually reply within 1 day
-
comp-s3queue
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
ClickHouse/ClickHouse#137649 ·
Maintainers usually reply within 1 day
-
area/docdb kind/enhancement mvu-pg15-pg19 priority/low
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
yugabyte/yugabyte-db#40355 ·
Maintainers usually reply within 1 day
-
Clear params.inputs in dials.indexPossibly taken @phyy-nx claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
dials/dials#3361 · 1 comment ·
Maintainers usually reply within 1 day