|
1 | 1 | use crate::{config::Config, queries::Query}; |
2 | 2 | use core::fmt; |
3 | 3 | use mysql::{prelude::Queryable, Conn, OptsBuilder}; |
| 4 | +use std::time::Duration; |
4 | 5 |
|
5 | 6 | #[allow(dead_code)] |
6 | 7 | /// Defines the possible status of a host |
@@ -68,7 +69,10 @@ impl Host { |
68 | 69 | .tcp_port(port) |
69 | 70 | .user(Some(config.readyset_user.clone())) |
70 | 71 | .pass(Some(config.readyset_password.clone())) |
71 | | - .prefer_socket(false), |
| 72 | + .prefer_socket(false) |
| 73 | + .read_timeout(Some(Duration::from_secs(5))) |
| 74 | + .write_timeout(Some(Duration::from_secs(5))) |
| 75 | + .tcp_connect_timeout(Some(Duration::from_secs(5))), |
72 | 76 | ) { |
73 | 77 | Ok(conn) => conn, |
74 | 78 | Err(err) => { |
@@ -144,14 +148,22 @@ impl Host { |
144 | 148 | pub fn check_readyset_is_ready(&mut self) -> Result<bool, mysql::Error> { |
145 | 149 | match &mut self.conn { |
146 | 150 | Some(conn) => { |
147 | | - let rows: Vec<(String, String)> = |
148 | | - conn.query("SHOW READYSET STATUS").unwrap_or(vec![]); |
149 | | - for (field, value) in rows { |
150 | | - if field == "Snapshot Status" { |
151 | | - return Ok(value == "Completed"); |
| 151 | + let result = conn.query("SHOW READYSET STATUS"); |
| 152 | + match result { |
| 153 | + Ok(rows) => { |
| 154 | + let rows: Vec<(String, String)> = rows; |
| 155 | + for (field, value) in rows { |
| 156 | + if field == "Snapshot Status" { |
| 157 | + return Ok(value == "Completed"); |
| 158 | + } |
| 159 | + } |
| 160 | + Ok(false) |
152 | 161 | } |
| 162 | + Err(err) => Err(mysql::Error::IoError(std::io::Error::new( |
| 163 | + std::io::ErrorKind::Other, |
| 164 | + format!("Failed to execute query: {}", err), |
| 165 | + ))), |
153 | 166 | } |
154 | | - Ok(false) |
155 | 167 | } |
156 | 168 | None => Err(mysql::Error::IoError(std::io::Error::new( |
157 | 169 | std::io::ErrorKind::Other, |
|
0 commit comments