Skip to content

jsonrpc: add two functions, but they don't compile yet, being not "threadsafe" #3591

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Conversation

Simon-Laux
Copy link
Contributor

@Simon-Laux Simon-Laux commented Sep 9, 2022

these two functions don't compile, I get this error:

error: generator cannot be sent between threads safely
  --> deltachat-jsonrpc/src/api/mod.rs:74:1
   |
74 | #[rpc(all_positional, ts_outdir = "typescript/generated")]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future created by async block is not `Send`
   |
   = help: the trait `Sync` is not implemented for `core::fmt::Opaque`
   = note: required for the cast to the object type `dyn Future<Output = Result<Value, yerpc::Error>> + Send`
   = note: this error originates in the attribute macro `rpc` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `deltachat-jsonrpc` due to previous error
cargo failed with code 101

any ideas what we need to change in order to fix it?

also if you try it out, I recommend uncommenting one of those functions because both have similar errors so you might not notice at a glance if you
fixed it.

@Hocuri
Copy link
Collaborator

Hocuri commented Sep 10, 2022

For the get_connectivity_html() problem: The problem is that #[rpc(...)] requires all futures to be Send, so you can't hold a fmt argument over an await point, so you can't use await in format!.

I found this out by commenting parts of get_connectivity_html() until I knew where the error was, and by using rust-analyzer's Expand macro recursively on the #[rpc(...)]. I think the Rust compiler could handle this better; I created a reproducible example at https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=d20021c1f59736781ee3641d50797820 and will report this upstream, maybe it's fixable (maybe not, we'll see).

You will have to replace all these code parts:

        ret += &format!(
            "<h3>{}</h3><ul><li>",
            stock_str::outgoing_messages(self).await
        );

by e.g.:

        let stock_outgoing_msgs = stock_str::outgoing_messages(self).await;
        ret += &format!("<h3>{}</h3><ul><li>", stock_outgoing_msgs);

I didn't look at the other problem yet, or maybe you can fix it yourself.

@Jikstra
Copy link
Contributor

Jikstra commented Sep 10, 2022

Fixed them thanks to @Hocuri discoveries :)

@Jikstra Jikstra merged commit f3a38d7 into jsonrpc-add-missing-functions-for-making-message-list-work-in-desktop Sep 10, 2022
@Jikstra Jikstra deleted the jsonrpc-func-failing-to-compile-lets-find-out-why branch September 10, 2022 13:58
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants