I am facing a strange problem when spwaning threads in the rust code. After spawning a thread for processing, the code binds to a UDS and accepts connections.
This code prints the "Bind Successful " message but just hangs without accepting connection from the UDS.
If the code for spawning the thread is commented out, the code works, prints the BIND successful message and if there are connections from the client, accepts and processes it.
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// initializations
let mut time_old = Instant::now();
tokio::spawn(async move{
loop {
let time_now = Instant::now();
match time_now.checked_duration_since(time_old)
{
time_old = Instant::now();
// process code here
};
}
});
// more processing here
let mut listener_res = UnixListener::bind(&socket);
if listener_res.is_err() {
// Socket is being used by somebody else
}
match listener_res {
Ok(listener)=>{
info!("Bind successful{}!",socket.display());
match listener.accept().await { // **The code hangs here **
Ok(listener)=>{
// Process this code
}
Err => {
// Error on socket
}
}
}
}
Not able to pointout what is wrong in the thread model. Are there any ways to debug tokio/async code? Any help will be appreciated.