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

karyon_jsonrpc failed to be built on rust 1.64.0 #5

Closed
weiyuhang2011 opened this issue Jun 29, 2024 · 2 comments
Closed

karyon_jsonrpc failed to be built on rust 1.64.0 #5

weiyuhang2011 opened this issue Jun 29, 2024 · 2 comments
Labels
enhancement New feature or request jsonrpc

Comments

@weiyuhang2011
Copy link

I tried to build a simple jsonrpc server using karyon_jsonrpc from https://github.com/karyontech/karyon/blob/master/jsonrpc/examples/pubsub_server.rs with rust 1.64.0. It failed with following errors:

❯ cargo +1.64.0 build
   Compiling karyon_jsonrpc v0.1.4
error: future cannot be sent between threads safely
   --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/karyon_jsonrpc-0.1.4/src/server/mod.rs:258:25
    |
258 |         self.task_group.spawn(
    |                         ^^^^^ future created by async block is not `Send`
    |
    = help: the trait `Sync` is not implemented for `dyn Fn(Arc<Channel>, std::string::String, Value) -> Pin<Box<dyn Future<Output = std::result::Result<Value, RPCError>> + Sync + std::marker::Send>> + std::marker::Send`
note: future is not `Send` as this value is used across an await
   --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/karyon_jsonrpc-0.1.4/src/server/mod.rs:293:80
    |
293 |                 response.result = match method(channel, req.msg.method, params).await {
    |                                         ------                                 ^^^^^^ await occurs here, with `method` maybe used later
    |                                         |
    |                                         has type `&Box<dyn Fn(Arc<Channel>, std::string::String, Value) -> Pin<Box<dyn Future<Output = std::result::Result<Value, RPCError>> + Sync + std::marker::Send>> + std::marker::Send>` which is not `Send`
...
296 |                 };
    |                  - `method` is later dropped here
help: consider moving this into a `let` binding to create a shorter lived borrow
   --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/karyon_jsonrpc-0.1.4/src/server/mod.rs:293:41
    |
293 |                 response.result = match method(channel, req.msg.method, params).await {
    |                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `TaskGroup::spawn`
   --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/karyon_core-0.1.4/src/async_util/task_group.rs:62:35
    |
62  |         Fut: Future<Output = T> + Send + 'static,
    |                                   ^^^^ required by this bound in `TaskGroup::spawn`

error: future cannot be sent between threads safely
   --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/karyon_jsonrpc-0.1.4/src/server/mod.rs:258:25
    |
258 |         self.task_group.spawn(
    |                         ^^^^^ future created by async block is not `Send`
    |
    = help: the trait `Sync` is not implemented for `dyn Fn(Value) -> Pin<Box<dyn Future<Output = std::result::Result<Value, RPCError>> + Sync + std::marker::Send>> + std::marker::Send`
note: future is not `Send` as this value is used across an await
   --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/karyon_jsonrpc-0.1.4/src/server/mod.rs:307:55
    |
307 |                 response.result = match method(params).await {
    |                                         ------        ^^^^^^ await occurs here, with `method` maybe used later
    |                                         |
    |                                         has type `&Box<dyn Fn(Value) -> Pin<Box<dyn Future<Output = std::result::Result<Value, RPCError>> + Sync + std::marker::Send>> + std::marker::Send>` which is not `Send`
...
310 |                 };
    |                  - `method` is later dropped here
help: consider moving this into a `let` binding to create a shorter lived borrow
   --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/karyon_jsonrpc-0.1.4/src/server/mod.rs:307:41
    |
307 |                 response.result = match method(params).await {
    |                                         ^^^^^^^^^^^^^^
note: required by a bound in `TaskGroup::spawn`
   --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/karyon_core-0.1.4/src/async_util/task_group.rs:62:35
    |
62  |         Fut: Future<Output = T> + Send + 'static,
    |                                   ^^^^ required by this bound in `TaskGroup::spawn`

error[E0599]: no method named `leak` found for struct `std::string::String` in the current scope
  --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/karyon_jsonrpc-0.1.4/src/error.rs:62:46
   |
62 |         Error::ChannelSend(error.to_string().leak())
   |                                              ^^^^ method not found in `std::string::String`

error[E0599]: no method named `leak` found for struct `std::string::String` in the current scope
  --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/karyon_jsonrpc-0.1.4/src/error.rs:89:48
   |
89 |         RPCError::ParseError(error.to_string().leak())
   |                                                ^^^^ method not found in `std::string::String`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `karyon_jsonrpc` due to 4 previous errors

But it works on stable toolchain.

@hozan23
Copy link
Member

hozan23 commented Jun 30, 2024

Hello @weiyuhang2011
Sorry to hear that. I have published a new update that fixes this issue along with other changes and fixes. Please update to the latest version on crates.io, and it should work fine.

@hozan23 hozan23 added bug Something isn't working jsonrpc enhancement New feature or request and removed bug Something isn't working labels Jun 30, 2024
@weiyuhang2011
Copy link
Author

It works now! THX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request jsonrpc
Projects
None yet
Development

No branches or pull requests

2 participants