kubo / rust-oracle

Oracle driver for Rust
189 stars 44 forks source link

Usage with asynchronous code problem - how to shut down `.connect()` call that hangs indefinitely #66

Closed Niedzwiedzw closed 1 year ago

Niedzwiedzw commented 1 year ago

My problem now is that some of the connections just hang indefinitely. my code:

#[instrument(skip_all)]
async fn acquire_connection(
    OracleConnectionCredentials {
        username,
        password,
        connect_string,
    }: OracleConnectionCredentials,
) -> Result<Arc<Connection>> {
    tokio::task::spawn_blocking(move || {
        debug!("getting connection out of a pool");
        let conn = oracle::Connector::new(username, password, connect_string)
            .purity(oracle::conn::Purity::New)
            .connect()
            .map(Arc::new);
        conn
    })
    .await
    .wrap_err("thread crashed")
    .and_then(|v| v.wrap_err("acquiring"))
}

can I either give it some timeout or break this process externally?

Niedzwiedzw commented 1 year ago

more context: .connect() hangs with 1 (!) database out ot 113 databases I'm connecting to. internet connection is surprisingly OK for this one (5MB/s upload and download). restarting my backend fixes it temporarily (1 connection works) , but next connection fails.

this could also be random, but I can't help but suspect that there is some internal state in my app that's left over after the procedure that "stuffs" next conections

kubo commented 1 year ago

How about setting SQLNET.OUTBOUND_CONNECT_TIMEOUT in sqlnet.ora?

Niedzwiedzw commented 1 year ago

sadly I have no control over that database's configuration...

Niedzwiedzw commented 1 year ago

would it be hard to add a timeout to .connect() in oracle-rust ?

cjbj commented 1 year ago

sadly I have no control over that database's configuration...

You would set SQLNET.OUTBOUND_CONNECT_TIMEOUT in sqlnet.ora on the machine where you run Rust, not on the database tier. The potential locations for the file can be gleaned from this doc.

Niedzwiedzw commented 1 year ago

OH!!!! yes it worked ,thank you so much @cjbj you just saved my project, you are the best