Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible issue when typechecking code? #122499

Closed
CR7273868 opened this issue Mar 14, 2024 · 3 comments
Closed

Possible issue when typechecking code? #122499

CR7273868 opened this issue Mar 14, 2024 · 3 comments
Labels
S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress.

Comments

@CR7273868
Copy link

CR7273868 commented Mar 14, 2024

There is an issue retaining for me with Rust cycle detected when computing type of opaque:

cycle detected when computing type of opaque `handlers::controllers::on_authenticated::on_authenticated::{opaque#0}`
...which again requires computing type of opaque `handlers::controllers::on_authenticated::on_authenticated::{opaque#0}`, completing the cycle
see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more informationrustc[Click for full compiler diagnostic](rust-analyzer-diagnostics-view:/diagnostic%20message%20%5B4%5D?4#file%3A%2F%2F%2Froot%2Fsocket_bot_rs%2Fsrc%2Fhandlers%2Fcontrollers%2Fon_authenticated.rs)
on_authenticated.rs(13, 1): ...which requires borrow-checking `handlers::controllers::on_authenticated::on_authenticated`...
on_authenticated.rs(18, 17): ...which requires borrow-checking `handlers::controllers::on_authenticated::on_authenticated::{closure#0}`...
lib.rs(1, 1): ...which requires evaluating `type_op_prove_predicate` `ProvePredicate { predicate: Binder { value: TraitPredicate(<{async block@src/handlers/controllers/on_authenticated.rs:55:22: 55:90} as core::marker::Send>, polarity:Positive), bound_vars: [] } }`...
lib.rs(1, 1): ...which requires evaluating trait selection obligation `{async block@src/handlers/controllers/on_authenticated.rs:55:22: 55:90}: core::marker::Send`...
scanner.rs(14, 1): ...which requires computing type of opaque `runners::scanner::scan_rooms::{opaque#0}`...
scanner.rs(14, 1): ...which requires borrow-checking `runners::scanner::scan_rooms`...
scanner.rs(17, 33): ...which requires borrow-checking `runners::scanner::scan_rooms::{closure#0}`...
scanner.rs(75, 30): ...which requires borrow-checking `runners::scanner::scan_rooms::{closure#0}::{closure#4}`...
lib.rs(1, 1): ...which requires evaluating `type_op_prove_predicate` `ProvePredicate { predicate: Binder { value: TraitPredicate(<{async block@src/runners/scanner.rs:78:42: 78:98} as core::marker::Send>, polarity:Positive), bound_vars: [] } }`...
lib.rs(1, 1): ...which requires evaluating trait selection obligation `{async block@src/runners/scanner.rs:78:42: 78:98}: core::marker::Send`...
socket_bot.rs(20, 5): ...which requires computing type of opaque `types::socket_bot::<impl at src/types/socket_bot.rs:19:1: 19:15>::new::{opaque#0}`...
socket_bot.rs(20, 5): ...which requires borrow-checking `types::socket_bot::<impl at src/types/socket_bot.rs:19:1: 19:15>::new`...
socket_bot.rs(23, 23): ...which requires borrow-checking `types::socket_bot::<impl at src/types/socket_bot.rs:19:1: 19:15>::new::{closure#0}`...
lib.rs(1, 1): ...which requires evaluating `type_op_prove_predicate` `ProvePredicate { predicate: Binder { value: TraitPredicate(<{async block@src/types/socket_bot.rs:50:67: 70:10} as core::marker::Send>, polarity:Positive), bound_vars: [] } }`...
on_authenticated.rs(13, 1): cycle used when computing type of `handlers::controllers::on_authenticated::on_authenticated::{opaque#0}`

Code:
on_authenticated.rs

pub async fn on_authenticated(
    cancel_token: tokio_util::sync::CancellationToken,
    user: &crate::types::session::UserData,
    sender: &WebSocketSender,
    state: &Arc<AppState>,
) -> Result<()> {
    let token = cancel_token.clone();
    let sender = sender.clone();
    tokio::spawn(async move {
        let mut interval = tokio::time::interval(tokio::time::Duration::from_secs(5));
        tokio::pin!(cancel_token);
        loop {
            tokio::select! {
                _ = interval.tick() => {
                    if cancel_token.is_cancelled() {
                        break;
                    }
                    {
                        let message = IMQBaseMessage::new(
                            crate::types::imq::Records::Ping,
                            None,
                        );
                    sender
                        .lock()
                        .await
                        .send(tokio_websockets::Message::text(message.to_string()))
                        .await.unwrap_or_else(|e| {
                            eprintln!("Error sending ping aborting bot: {}", e);
                            cancel_token.cancel();
                        });
                    };
                }
                _ = cancel_token.cancelled() => {
                    break;
                }
            }
        }
    });

    let state = state.clone();
    let username = user.users.username.clone();
    let _: tokio::task::JoinHandle<Result<()>> =
        tokio::spawn(async move { scan_rooms_task(state.clone(), token, username).await });

    Ok(())
}

scanner.rs

pub async fn scan_rooms_task(
    mut state: Arc<AppState>,
    cancel_token: tokio_util::sync::CancellationToken,
    username: String,
) -> Result<()> {
    let mut interval = tokio::time::interval(tokio::time::Duration::from_secs(5));
    let mut count = 7;
    tokio::pin!(cancel_token);
    loop {
        tokio::select! {
            _ = interval.tick() => {
                count += 1;
                if count > 10 {
                    cancel_token.cancel();
                }
                if cancel_token.is_cancelled() {
                    return Ok(());
                }
                match scan_rooms(&mut state, &username).await {
                    Ok(_) => {}
                    Err((reason, kill)) => {
                        eprintln!("Error scanning rooms: {}", reason);
                        if kill {
                            cancel_token.cancel();
                        }
                    }
                };

            }
            _ = cancel_token.cancelled() => {
                break;
            }
        }
    }
    Ok(())
}

Cargo list:

[package]
name = "socket_bot_rs"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio = { version = "1.35.1", features = ["full"] }
serde = { version = "1.0.195", features = ["derive"] }
serde_json = "1.0.111"
futures = "0.3.30"
anyhow = "1.0.79"
reqwest = { version = "0.11.23", features = ["json"] }
async-recursion = "1.0.5"
flate2 = "1.0.28"
keshvar = {version = "0.3.0", features = ["emojis", "serde-derive", "search-country-code", "search-iso-short-name"]}
sqlx = {version = "0.7.3", features = ["runtime-tokio", "time", "postgres", "macros", "chrono", "tls-native-tls"]}
chrono = "0.4.33"
regex = "1.10.3"
once_cell = "1.19.0"
scc = { version = "2.0.17", features = ["serde"] }
html-escape = "0.2.13"
base64 = "0.13.0"
tokio-retry = "0.3"
tokio-websockets = {version = "0.7.0", features = ["simd", "client", "native-tls", "openssl", "rand"]}
dotenv = "0.15.0"
http = "1.1.0"
tokio-graceful-shutdown = "0.14.3"
tokio-util = "0.7.10"
[dependencies.uuid]
version = "1.6.1"
features = [
    "v4",                # Lets you generate random UUIDs
    "fast-rng",          # Use a faster (but still sufficiently random) RNG
    "macro-diagnostics", # Enable better diagnostics for compile-time UUIDs
]

Compiled using: 1.76-x86_64-unknown-linux-gnu unchanged - rustc 1.76.0 (07dca48 2024-02-04) (DEBUG)
Debian 12
Kernel: 5.10.0-28-amd64 #1 SMP Debian 5.10.209-2 (2024-01-31) x86_64 GNU/Linux

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 14, 2024
@workingjubilee
Copy link
Member

@Demy076 Please do not provide random excerpts from your code, but rather provide enough to actually replicate the error.

@compiler-errors
Copy link
Member

You should at least provide the body of the scan_rooms function that's mentioned in this cycle error. I don't believe we can really do much with this error report right now.

@jieyouxu jieyouxu added the S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress. label Mar 14, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 14, 2024
@workingjubilee
Copy link
Member

Without enough code to reproduce this error, I am closing this issue for now. Please feel free to reopen it if you can make the rest available.

@workingjubilee workingjubilee closed this as not planned Won't fix, can't repro, duplicate, stale Mar 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress.
Projects
None yet
Development

No branches or pull requests

6 participants