Blocking code issue (potential deadlock) for webserver

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):

Fixed. Added this code to main (replacing the existing portion of the function)

    println!("[DEBUG] Starting server connection task...");
    let server_connection_state = multifaceted_state.clone();
    let bridge_rx = multifaceted_state.read().await.tcp_rx.clone();
    let bridge_tx = multifaceted_state.read().await.ws_tx.clone();

    tokio::spawn(async move {
        println!("[DEBUG] Server connection task started");
        // **NO write().await here** — just pass the Arc
        if let Err(e) = connect_to_server(
            server_connection_state,
            bridge_rx,
            bridge_tx,
        ).await {
            eprintln!("[DEBUG] Connection task failed: {}", e);
        }
    });

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.