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

Boxed Queries are not thread safe. #1625

Closed
seunlanlege opened this Issue Apr 7, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@seunlanlege

seunlanlege commented Apr 7, 2018

Setup

Versions

  • Rust: rustc 1.26.0-nightly (ae544ee1c 2018-03-29)
  • Diesel: { version = "1.1.0" }
  • Database: postgres
  • Operating System

Feature Flags

  • diesel: ["postgres"]

Problem Description

disel

	let query = payments::table.filter(payments::company_id.eq(companyId)).into_boxed(); // adding `.into_boxed()` causes `query` to no longer be thread safe
	let future = async::query(move |conn| query.get_result::<models::Payment>(conn));

async::query will spawn the closure on a futures cpupool and requires that the closure contain thread safe items.

What are you trying to accomplish?

What is the expected output?

What is the actual output?

error[E0277]: the trait bound `diesel::query_builder::QueryFragment<diesel::pg::Pg>: std::marker::Send` is not satisfied
  --> src/services/paymenthistory/paymenthistory.rs:23:15
   |
23 |     let future = async::query(move |conn| query.get_result::<models::Payment>(conn));
   |                  ^^^^^^^^^^^^ `diesel::query_builder::QueryFragment<diesel::pg::Pg>` cannot be sent between threads safely
   |
   = help: the trait `std::marker::Send` is not implemented for `diesel::query_builder::QueryFragment<diesel::pg::Pg>`
   = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<diesel::query_builder::QueryFragment<diesel::pg::Pg>>`
   = note: required because it appears within the type `std::boxed::Box<diesel::query_builder::QueryFragment<diesel::pg::Pg>>`
   = note: required because it appears within the type `diesel::query_builder::BoxedSelectStatement<'_, (diesel::sql_types::BigInt, diesel::sql_types::BigInt, diesel::sql_types::BigInt, diesel::sql_types::BigInt, diesel::sql_types::BigInt, db::schema::db_enum_impl_Status::StatusMapping, diesel::sql_types::Text, diesel::sql_types::Text), db::schema::payments::table, diesel::pg::Pg>`
   = note: required because it appears within the type `[closure@src/services/paymenthistory/paymenthistory.rs:23:28: 23:81 query:diesel::query_builder::BoxedSelectStatement<'_, (diesel::sql_types::BigInt, diesel::sql_types::BigInt, diesel::sql_types::BigInt, diesel::sql_types::BigInt, diesel::sql_types::BigInt, db::schema::db_enum_impl_Status::StatusMapping, diesel::sql_types::Text, diesel::sql_types::Text), db::schema::payments::table, diesel::pg::Pg>]`
note: required by `db::async::query`
  --> src/db/async.rs:24:1
   |
24 | / pub fn query<T, F, R>(f: F) -> impl Future<Item = T, Error = result::Error>
25 | | where
26 | |     T: Send + 'static,
27 | |     F: FnOnce(&Conn) -> R + Send + 'static,
...  |
49 | |     })
50 | | }
   | |_^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
error: Could not compile `paysquare`.

To learn more, run the command again with --verbose.

Are you seeing any additional errors?

Steps to reproduce

Checklist

  • I have already looked over the issue tracker for similar issues.
@sgrif

This comment has been minimized.

Member

sgrif commented Apr 7, 2018

Thank you for the report. However, making boxed queries Send would require a major breaking change, and isn't likely to happen right now. I suggest waiting until the query has been moved into your closure to box it, or just constructing the query entirely on that thread.

@sgrif sgrif closed this Apr 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment