kubo/rust-oracle

connection.ping seems to never timeout

Jabulba opened this issue · 2 comments

The connection ping fn seems to never return when no connection to db is present. The sample code below hangs during the match for conn.ping() and never returns Ok nor Err

I was attempting to use the ping to check if the database is still available because we are having some network issues. Am I missing something here?

Sample code:

let conn = match Connection::connect(username, password, "localhost:1521/DB1") {
	Ok(c) => {c}
	Err(err) => {panic!("{:?}", err)}
};

let delay = std::time::Duration::from_secs(3);
loop {
	match conn.ping() {
		Ok(_) => { log::info!("Ping OK!"); }
		Err(err) => { log::info!("Ping Err: {:?}", err); }
	};

	std::thread::sleep(delay);
}
kubo commented

connection.ping works when the network isn't in trouble.
It sends a ping packet and waits the reply. However it hangs until timeout when the reply is lost by network trouble.
Could you use SQLNET.RECV_TIMEOUT or Connection.set_call_timeout() added in v0.3.3?

I tried with the new Connection.set_call_timeout() and it works nicely, thanks for the quick update!
I think it would also be nice to be able to configure the Connector with this option! I can try to make a PR if you like, but I'm still somewhat new with Rust