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

Can't use warp with an Rc (!Send) state (single-threaded executor) #1022

Open
SylvainGarrigues opened this issue Mar 5, 2023 · 3 comments
Open

Comments

@SylvainGarrigues
Copy link

SylvainGarrigues commented Mar 5, 2023

I'm am running warp as a service with a single-threaded hyper server.

The setup is based on:
https://github.com/hyperium/hyper/blob/0.14.x/examples/single_threaded.rs

which allows to use a state shared through an Rc pointer.

I am trying to port the warp todos example in this setup, with an Rc/Refcell because Arc is not needed, and I cannot because this line:

warp::any().map(move || db.clone())

creates a Map filter which does not implement warp::filter::FilterBase, because warp's implementation requires to use Send closures:

impl<T, F> FilterBase for Map<T, F>
where
    T: Filter,
    F: Func<T::Extract> + Clone + Send,

(see the Send trait on the last line - taken from https://github.com/seanmonstar/warp/blob/master/src/filter/map.rs).

It is so frustrating to use sync primitives (Arc / Mutex) when they are not needed!

Is there any workaround? Is the Send trait necessary there?

@seanmonstar
Copy link
Owner

I don't remember if the Send trait is needed. I assume it was added to make something else happy, if you wanted to try to remove it and see if the library still compiles...

@SylvainGarrigues
Copy link
Author

SylvainGarrigues commented Mar 5, 2023

I feel like it was introduced at that time:
79ead36#diff-ff6d351d5b8e9ccd8131a2368e902858310c79aa975f2ed11fd53c6b7da68817

Also the AndThen filter has the same Send requirement so I guess relaxing the Send trait only for Map won't help much :(

F: Func<T::Extract> + Clone + Send,

@SylvainGarrigues
Copy link
Author

SylvainGarrigues commented Mar 18, 2023

I don't remember if the Send trait is needed. I assume it was added to make something else happy, if you wanted to try to remove it and see if the library still compiles...

I had to remove + Send all around the place and even disable some code (e.g. warp server stuff) to make it compile without Send, so I am enclines to say there is no easy way to use warp with a single-threaded executor and a !Send state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants