Blocking code issue (potential deadlock) for webserver

⚓ rust    📅 2025-07-15    👤 surdeus    👁️ 2      

surdeus

I have blocking code
and I cant figure out how to fix the blocking code issue
but my webserver cannot work
i added debugging statements, I still do not know where it comes from, here is the code:

Here is the debug statements, i do not know what to make of it:

[DEBUG] Starting server...
[DEBUG] Establishing database connection...
[DEBUG] Loading configuration...
... (removed debug statements to save space from logs)
[DEBUG] Received capability response: {"list":["all"]}
[DEBUG] Sending server data request
[DEBUG] Received server data: {"list":["all"]}
{"authcode":"0","data":"{\"start_keyword\":\"help\",\"stop_keyword\":\"All dimensions are saved\"}","type":"info"}
[DEBUG] Entering main stream loop

This is the main stream loop but i dont know what could be blocking or deadlocked in there

    println!("[DEBUG] Entering main stream loop");

    loop {
        let mut rx_guard = rx.lock().await;
        tokio::select! {
            result = reader.read(&mut buf) => match result {
                Ok(0) => {
                    println!("[DEBUG] Stream read returned 0 bytes - connection closed");
                    return Ok(());
                },
                Ok(n) => {
                    println!("[DEBUG] Received {} bytes from stream", n);
                    handle_server_data(state.clone(), &buf[..n], &ws_tx).await?
                },
                Err(e) => {
                    println!("[DEBUG] Stream read error: {:?}", e);
                    return Err(e.into());
                },
            },
            result = rx_guard.recv() => if let Some(data) = result {
                println!("[DEBUG] Sending {} bytes to server", data.len());
                writer.write_all(&data).await?;
                writer.write_all(b"\n").await?;
                writer.flush().await?;
            } else {
                println!("[DEBUG] Channel closed - ending stream handling");
                return Ok(());
            }
        }
    }

Repo (if you need more context):

2 posts - 1 participant

Read full topic

🏷️ rust_feed