-
Notifications
You must be signed in to change notification settings - Fork 197
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
EspWebSocketClient
cannot be shared across threads
#546
Comments
If, by "sharing across threads" you mean What To prove this, remove the Now, if you want to use the client from two threads simultaneously, then you are reaching to something else called
This is too long to explain in details, but here the compiler is actually telling you that one reason |
Btw, |
Also just noticed the error message from the compiler mentioned |
If you are trying to use rwlock, use a mutex instead, because rwlock does not upgrade Send objects to Sync. See this: https://www.reddit.com/r/rust/comments/11fyjl7/why_is_rwlock_not_a_sync_maker/ |
Yeah, I tried to simplified the sample code for reproducing the issue, so I didn't copy my Thank you for clarifying the difference between I guess based on what you said, changing the Close this issue now. Thanks again 🙌 |
Do they? What happens if I call |
Ah, they seem to take a lock here. So it is only start/stop then which are problematic. |
Bug description
I am trying to build a websocket client that can be shared with different threads for sending data over. I thought the web socket client is thread safe, but I soon realized that despite
EspWebSocketClient
implementedSend
trait hereesp-idf-svc/src/ws/client.rs
Line 646 in 0115297
the underlying c struct
esp_websocket_client
stops me from really sharing it across threads. I assume theSend
trait forEspWebSocketClient
meant to make it safe to share across threads?Here are the sample code for reproducing it:
https://github.com/LaunchPlatform/esp-idf-svc-ws-client-cross-thread-bug/blob/f52412d1f8ce5a2a06c619713d4ab20609ae6443/src/main.rs#L18-L36
And the errors:
I tried to workaround it by making
esp_websocket_client
comply with Send as well likeBut it seems like Rust compiler doesn't allow me to do it in my own module, not sure if there's anything can be done in binding generation?
To Reproduce
Clone my repo and build
https://github.com/LaunchPlatform/esp-idf-svc-ws-client-cross-thread-bug
Expected behavior
It should allow
EspWebSocketClient
to be shared between threadsEnvironment
esp-idf-svc
) version: 0.50The text was updated successfully, but these errors were encountered: