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

chore: replace futures::mpsc with tokio::mpsc for Axum compatibility #4175

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mdqst
Copy link

@mdqst mdqst commented Apr 5, 2025

I replaced futures::mpsc::UnboundedSender with tokio::sync::mpsc::UnboundedSender in the Axum server setup. The original sender doesn't implement Sync, which causes issues when used with axum::extract::State.

tokio::mpsc::UnboundedSender implements Clone + Send + Sync + 'static, making it a better fit here and removing the need to wrap the sender in Arc<Mutex<...>>. The fix makes the enqueue route work as intended without extra boilerplate.

@mdqst mdqst requested a review from benluelo as a code owner April 5, 2025 16:24
Copy link

vercel bot commented Apr 5, 2025

@mdqst is attempting to deploy a commit to the unionbuild Team on Vercel.

A member of the Team first needs to authorize it.

@benluelo
Copy link
Contributor

benluelo commented Apr 5, 2025

thanks for the PR! was there an issue with the current design that this PR fixes? you mention Arc<Mutex<...>>, but we don't use that anywhere in the router.

@mdqst
Copy link
Author

mdqst commented Apr 8, 2025

Thanks for the feedback, benluelo! I encountered an issue when trying to use futures::mpsc::UnboundedSender with axum::extract::State, since the original sender does not implement Sync, which caused problems when working with multiple threads. Switching to tokio::sync::mpsc::UnboundedSender resolves this issue because it implements Sync, removing the need to wrap the sender in Arc<Mutex<...>>, as would be required with futures::mpsc. This change helps avoid potential concurrency issues and simplifies the code without introducing extra boilerplate.

@benluelo
Copy link
Contributor

I'm still not sure what problem you're trying to solve? The code works as it is right now.

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

Successfully merging this pull request may close these issues.

2 participants