1,280 questions
0
votes
0
answers
19
views
Actix-web + Tokio: Server hangs when using tokio::spawn with Arc<Mutex> loop
I am facing an issue where my Actix-web server starts correctly, but the moment I hit the /upload_chunk endpoint from my frontend, the request hangs forever.
After some debugging, I found that the ...
Advice
0
votes
1
replies
71
views
Thread lifetime in Tokio Runtime
I have two questions about thread lifetime in Tokio Runtime. Based on Tokio documentation
While the Runtime is active, threads may shut down after periods of being idle.
It means (it is my ...
6
votes
1
answer
153
views
Is it safe to update an UnsafeCell while holding an &T reference?
I have a rust program where:
I only use one thread to run my entire application. #[tokio::main(flavor = "current_thread")]. I never spawn new threads only via tokio.
I hold all my models ...
0
votes
1
answer
80
views
Spawning multiple tasks but inner function is not executed without error message
I'm trying to spawn multiple parallel (not concurrent) tasks. Every task is running a PUT operation to a custom S3 storage using AWS SDK for Rust.
The function body looks the following (the different ...
2
votes
2
answers
100
views
Sharing mutable reference in multiple select! branches
Since tokio::select! runs all branches concurrently but not in parallel, why doesn't Rust allow branches to share the same mutable reference ? Is there a way to solve this problem ?
Example of code ...
3
votes
1
answer
114
views
How to kill a task that runs alongside the main program?
I have the following code where I start an Actix Web server and a queue handler task.
When I press Ctrl+C, I want both the HTTP server and the queue handler to shut down gracefully.
Currently, the ...
1
vote
1
answer
54
views
Send big `tokio::fs::File` as response body with hyper 1.0 (in a streaming fashion)
I am writing a static file server with hyper 1.0 and tokio 1.0. When serving a file, I want it to be as fast as possible while allocating the minimum required amount of memory. In other words: I want ...
0
votes
2
answers
122
views
Reduced parallelism on first RPC (on blocking code)
Setup
I'm playing with tonic helloworld tutorial.
The only changes I made is that in say_hello, just before returning the reply, I added:
std::thread::sleep(std::time::Duration::from_millis(10000));
...
0
votes
1
answer
104
views
How to spawn a thread only one time and being able to update some values
I have a web server with Axum, and when I receive a call to, let's say my endpoint start, I want to start a process that can be stopped by calling a second endpoint stop.
If I call a second time the ...
0
votes
1
answer
64
views
libp2p request_reponse UnexpectedEof error
I am working with rust-libp2p and I'm using libp2p request_reponse, but I found out that the send_reponse method from the network behaviour doesn't actually send when the file is large(43 MB in my ...
0
votes
0
answers
66
views
MPSC Channel filled and draind by the same loop not terminating
Consider a Webcrawler which will start of an entry point and put found links into its own queue for further processing.
Sequential implementation
A working sequential implementation may be like the ...
2
votes
2
answers
171
views
What's the difference between cloning an mpsc::Sender and wrapping it in Arc for sharing between threads?
I'm building a Rust client that includes a Sender field:
struct Client {
tx: std::sync::mpsc::Sender<String>,
some_other_stuff: i32,
}
To share this Client between threads, I wrapped it ...
0
votes
1
answer
97
views
Issues with Box<dyn> and tokio tracing subscriber
I am working with the tokio tracing/tracing_subscriber crates building an internal toolkit and have been running into issues trying to add an option to pass a custom formatter to the layer.
Using the ...
1
vote
2
answers
89
views
Reducing boilerplate error mapping when constrained by the orphan rule
I am working on a project in which I'm using methods from a number of crates Foo1, Foo2, etc., returning objects like Result<T,Foo1Error>, Result<T,Foo2Error>, respectively, within an ...
-1
votes
1
answer
68
views
How do I move a Sender object out of a mutable reference to a Vector of tuples of Strings and Sender Objects?
This is not a solution to my problem. The suggested answer replaces the values with Nones. I quite literally require the size of my vector to reduce.
MRE:
use tokio::sync::mpsc;
#[tokio::main]
async ...
2
votes
1
answer
689
views
How to run async function in sync in tokio runtime?
I would like to initialize SeaOrm database connection in sync for easier usage inside application and testing, but not sure how to do it without error. I'm fine with any type of blocking as this ...
0
votes
1
answer
85
views
How to understand GLIBC incompatibility?
Unfortunately a project I'm working on doesn't work on some platforms. It crashes with an error like
/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found
/lib/x86_64-linux-gnu/libm.so.6: ...
1
vote
0
answers
73
views
How to temporarily increase logging level for tracing in a tracing / test-log unittest
I'm writing tests for a Rust program that uses the tracing crate for logging, and the test-log crate to enable logging in the tests.
I have an arrange step that does quite a lot of things, which I ...
-1
votes
1
answer
109
views
async tauri command returning dynamic error, does not implement necessary traits
im trying to give a client application email functionality using lettre and tokio.
The code itself should work, though declaring the function a tauri::command gives problems, i don't know how to solve....
1
vote
1
answer
96
views
How to get the file/seek position of a file opened in a thread asynchronously
In the below code I'm copying a file(worker thread) and want to print the progress of the file copy operation in main thread. I would like to know, if it's possible to get the file/seek position of ...
-1
votes
2
answers
160
views
Iterating over tokio directory entries
I understand the problem with this code, but I don't know what would be the right way to fix it:
use tokio::fs::read_dir;
use hyper::{Body, Response, Result};
async fn list_dir() -> Result<...
0
votes
0
answers
36
views
What is the difference between two tokio::spawn usages? [duplicate]
I’m currently learning Tokio from its official tutorial, and the following code is part of the tutorial: https://tokio.rs/tokio/tutorial/spawning
use mini_redis::{Connection, Frame};
use tokio::net::{...
4
votes
1
answer
485
views
Using `AsyncFnOnce` with `tokio::spawn`
When using AsyncFnOnce with tokio::spawn, I get the following error:
fn spawn_asyncfn<F>(f: F) -> tokio::task::JoinHandle<()>
where
F: 'static + AsyncFnOnce() -> (),
{
let ...
0
votes
1
answer
224
views
How do I encapsulate waiting for a `tokio::sync::watch::Receiver` to be `Some`?
I'd like to write an async function recv_some which takes a watch::Receiver<Option<T>>, waits for the value to be Some, and returns something which Deref's to T. For reasons I sort of ...
1
vote
1
answer
263
views
Can I prevent task stealing in multithreaded Tokio?
As I understand it, with the multithreaded runtime a Tokio task may be moved from worker thread to worker thread during its execution via the task stealing mechanism
Is there any way to tell the ...