-
Notifications
You must be signed in to change notification settings - Fork 25
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
feat: Make rs-wnfs work in multithreaded contexts #372
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #372 +/- ##
==========================================
+ Coverage 56.70% 56.89% +0.19%
==========================================
Files 45 45
Lines 3333 3334 +1
Branches 832 830 -2
==========================================
+ Hits 1890 1897 +7
+ Misses 886 884 -2
+ Partials 557 553 -4
|
Also: Remove unneeded `Sync` bounds left over from previous commits.
Replaces #368 |
TODO:
|
This relaxes the requirement if you're not on the `wasm32` target. The problem is that foreign types in Wasm don't implement `Sync`.
BlockStore
Send
and Sync
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks great! Do you plan to do a version bump and release in another PR?
Yep. Soon-ish ✌️ |
The main goal of this PR is to enable using rs-wnfs in multithreaded contexts, e.g. in axum webservers.
We have a test repo to check whether that works in an MVP: https://github.com/fabricedesre/wnfs-mtload/
Previously that wasn't possible, since the async futures from rs-wnfs weren't
Send
, so you couldn't have a multi-threaded work-stealing async runtime work on them.The reasons they weren't sync were:
impl BlockStore
, and it's not necessarily known to beSend
impl PrivateForest
with the same problemLocalBoxFuture
orLocalBoxStream
, which aren'tSend
async_trait(?Send)
andasync_recursion(?Send)
which opt-in to not havingSend
bounds, since that's what we need for wasmPrivateNode
, which would useRc
internally instead ofArc
, see also Refactor: Consider switching fromRc
toArc
#250Some of this work was already addressed in #366. This PR should cover the rest.
There's a complication with Wasm, where we're e.g. using an external type
extern "C" { type BlockStore; ... }
, which isn'tSend
orSync
, and as such can't ever implement atrait BlockStore: Send + Sync
.To fix this, we're conditionally compiling in
Send
andSync
bounds (andArc
andRc
and similar) based on the target (Seesend_sync_poly.rs
). This is pretty much just copying what noosphere is doing: https://github.com/subconsciousnetwork/noosphere/blob/main/rust/noosphere-common/src/sync.rsI'm hoping eventually we just fix this and thus enable multi-threaded Wasm, too. But for now this works.