You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since Rocket requires the data it manages to be thread-safe, I encountered an issue where the Juniper Schema containing a thread-safe database pool would not be recognised as implementing Sync. I've initially opened an issue at the Rocket repo.
The gist is that I would get blocked by a compile error:
error[E0277]: `std::cell::Cell<i32>` cannot be shared between threads safely
--> src/api.rs:27:1
|
27 | / fn post_graphql_handler(
28 | | context: Database,
29 | | request: juniper_rocket::GraphQLRequest,
30 | | schema: State<Schema>,
31 | | ) -> juniper_rocket::GraphQLResponse {
32 | | request.execute(&schema, &context)
33 | | }
| |_^ `std::cell::Cell<i32>` cannot be shared between threads safely
|
= help: within `juniper::schema::model::RootNode<'static, store::Query, juniper::types::scalars::EmptyMutation<store::Context>>`, the trait `std::marker::Sync` is not implemented for `std::cell::Cell<i32>`
= note: required because it appears within the type `diesel::connection::AnsiTransactionManager`
= note: required because it appears within the type `diesel::SqliteConnection`
= note: required because it appears within the type `rocket_contrib::databases::r2d2::Conn<diesel::SqliteConnection>`
= note: required because it appears within the type `std::option::Option<rocket_contrib::databases::r2d2::Conn<diesel::SqliteConnection>>`
= note: required because it appears within the type `diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::SqliteConnection>>`
= note: required because it appears within the type `store::db::Database`
= note: required because it appears within the type `store::Context`
= note: required because it appears within the type `std::marker::PhantomData<store::Context>`
= note: required because it appears within the type `juniper::types::scalars::EmptyMutation<store::Context>`
= note: required because it appears within the type `juniper::schema::model::RootNode<'static, store::Query, juniper::types::scalars::EmptyMutation<store::Context>>`
= note: required by `rocket::State`
This is surprising, because the store::db::Database type actually implements Sync. I found that I could resolve the issue by not using juniper::EmptyMutation but instead doing
Because EmptyMutation never references T...it only uses it for PhantomData. That being said, I am unsure as I have never used unsafe in Rust before. @theduke ?
Since Rocket requires the data it manages to be thread-safe, I encountered an issue where the Juniper
Schema
containing a thread-safe database pool would not be recognised as implementingSync
. I've initially opened an issue at the Rocket repo.The gist is that I would get blocked by a compile error:
This is surprising, because the
store::db::Database
type actually implementsSync
. I found that I could resolve the issue by not usingjuniper::EmptyMutation
but instead doingTherefore, I assume that there is a bug in the implementation of
EmptyMutation
that prevents correct inference of theSync
trait.While it is not a self-contained example, the error is present on this commit and is fixed in this commit.
The text was updated successfully, but these errors were encountered: