-
Notifications
You must be signed in to change notification settings - Fork 56
Open
Description
Sometimes the Characteristic::write() just never returns and hangs the entire Tokio runtime.
For example I call the function from a non async context like this
tokio::task::block_in_place(|| {
let rt = tokio::runtime::Handle::current();
rt.block_on(characteristic.write(data))
})That generally works, but ever 50 or so calls the function just hangs the entire process.
As block_in_place() can have some issues I've also tried spawning a Tokio task to handle the write
// Create write queue channel
let (write_tx, mut write_rx) = mpsc::unbounded_channel::<WriteRequest>();
// Spawn write worker thread
tokio::spawn(async move {
println!("📝 BLE Write worker thread started");
while let Some(req) = write_rx.recv().await {
let result = req.characteristic.write(&req.data).await;
let _ = req.response_tx.send(result);
}
panic!("📝 BLE Write worker thread stopped");
}); and then pass the write to the task like this
self.write_tx.send(write_req)?;
// Block waiting for the worker thread to complete the write
let result = tokio::task::block_in_place(|| {
tokio::runtime::Handle::current().block_on(response_rx)
})which is more robust, but eventuall also hangs.
tokio-console doesn't offer much as I can't see where in Characteristic::write() the hang occurs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels