-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
"dispatch dropped without returning error" when using Client from tests #2112
Comments
The |
So what is the best way to write tests that use a global client? #[tokio::test] uses differrent executors by default. |
Why do you need to use a global client? |
I would highly recommend not using a global client but instead creating a client per test. This is what we do for most of our tests in https://github.com/timberio/vector/ and works great. |
@LucioFranco That would require a major breaking API change for my library and make it more complex. I would rather not, but if it is the only way to make tests work when multi-threaded then I will. |
I know |
@Koxiaet I ran into a similar issue when using the same reqwest client for several integration tests. The client does some authentication and I wanted to avoid running that on every test. I ended up using a Mutex. You can find the code here: https://github.com/roignpar/thetvdb/blob/master/tests/client.rs |
@LucioFranco Did you manage to find a solution for testing Rusoto? My current workaround is to limit the number of threads for my tests to 1. It would be nice if it can somehow be resolved.. |
We are hitting the same panic when testing with If there's any other other way rather than running these tests with the thread limit set to 1, it would be nice to hear! (And of course other than wrapping the client into a Mutex) |
For rusoto you can create a new client https://docs.rs/rusoto_core/0.43.0/rusoto_core/request/struct.HttpClient.html from here and then pass that into the specific service's constructor. This will avoid using the |
@LucioFranco That was it! |
@LucioFranco amazing! Thank you very much |
I had a similar issue and ended up removing the client as a global and using multiple ones. Why is the client marked as thread-safe when it isn't? Shouldn't it implement Do I open a new issue about this? |
There is an [issue](hyperium/hyper#2112) on the hyper repo that matches an [exception](https://rollbar.com/sagemaker-rollbar/re_dms/items/76/?item_page=0&item_count=100&#traceback) we've been encountering in re_dms. The comments in the issue suggest that hyper does not support sharing a client across threads. Changing our implementation to create a new Rollbar client for each panic to see if that prevents this particular issue from occurring in the future.
There is an [issue](hyperium/hyper#2112) on the hyper repo that matches an [exception](https://rollbar.com/sagemaker-rollbar/re_dms/items/76/?item_page=0&item_count=100&#traceback) we've been encountering in re_dms. The comments in the issue suggest that hyper does not support sharing a client across threads. Changing our implementation to create a new Rollbar client for each panic to see if that prevents this particular issue from occurring in the future.
ref hyperium/hyper#2112, close #14285 Download tasks will executed in a tiny runtime for now. Signed-off-by: hillium <yujuncen@pingcap.com>
…14299) ref hyperium/hyper#2112, close #14285, ref #14286 Download tasks will executed in a tiny runtime for now. Signed-off-by: hillium <yujuncen@pingcap.com> Co-authored-by: hillium <yujuncen@pingcap.com>
My library uses a global
Client
to run its requests.The following code:
With tokio 0.2.9, hyper 0.13.1 and lazy_static 1.4.0, generates 10 tests, t1-t10, with each one making a simple request using a global client. Every
cargo test
, a random number of them panic with this backtrace.This has been reported before, but was closed by the author.
The error seems to be that I am using the same Client from different runtimes on different threads.
The text was updated successfully, but these errors were encountered: