Skip to content

Commit e8a2474

Browse files
authored
fix: Add drop task initial connect retry (#45)
Drop task can "see" server in crashed state in recovery tests during initial connect. This PR add retries so drop task will wait until server comes up in unlucky case.
1 parent 613c976 commit e8a2474

3 files changed

Lines changed: 29 additions & 5 deletions

File tree

sqllogictest-bin/src/main.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,31 @@ async fn drop_task(
850850
) -> Result<()> {
851851
const MAX_RETRIES: usize = 1;
852852
const RETRY_DELAY: Duration = Duration::from_secs(1);
853-
let mut db = engines::connect(&engine, &config, SslMode::Disable, DBPort::Plain).await?;
853+
// Recovery tests intentionally crash the server, and the
854+
// dropper's startup connect runs concurrently with the test -- it can be in
855+
// flight when that crash kills the server, surfacing as a one-off
856+
// "connection closed".
857+
// CONNECT_RETRIES is deliberately much larger than MAX_RETRIES because the
858+
// two cover different situations. The DROP runs *after* the test, when the
859+
// server is already back up. This
860+
// connect can instead land *during* the crash/restart window, when the
861+
// server is genuinely down, so it must keep trying long enough to outlast a
862+
// full restart -- many more attempts than reconnecting to an already-up
863+
// server.
864+
const CONNECT_RETRIES: usize = 10;
865+
let mut connect_attempts = 0;
866+
let mut db = loop {
867+
match engines::connect(&engine, &config, SslMode::Disable, DBPort::Plain).await {
868+
Ok(conn) => break conn,
869+
Err(e) => {
870+
connect_attempts += 1;
871+
if connect_attempts > CONNECT_RETRIES {
872+
return Err(e.into());
873+
}
874+
tokio::time::sleep(RETRY_DELAY).await;
875+
}
876+
}
877+
};
854878

855879
while let Some(message) = drop_rx.recv().await {
856880
match message {

sqllogictest-engines/src/postgres/extended.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ impl<'a> FromSql<'a> for TimestampValue {
244244
return Ok(TimestampValue("-infinity".into()));
245245
}
246246
}
247-
Ok(TimestampValue(NaiveDateTime::from_sql(ty, raw)?.to_string()))
247+
Ok(TimestampValue(
248+
NaiveDateTime::from_sql(ty, raw)?.to_string(),
249+
))
248250
}
249251

250252
accepts!(TIMESTAMP);

sqllogictest/src/substitution.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ fn escape_bare_dollars(input: &str) -> String {
4444
let mut out = String::with_capacity(input.len());
4545
let mut chars = input.chars().peekable();
4646
while let Some(c) = chars.next() {
47-
if c == '$'
48-
&& !matches!(chars.peek(), Some(&('{' | 'a'..='z' | 'A'..='Z' | '_')))
49-
{
47+
if c == '$' && !matches!(chars.peek(), Some(&('{' | 'a'..='z' | 'A'..='Z' | '_'))) {
5048
out.push('\\');
5149
}
5250
out.push(c);

0 commit comments

Comments
 (0)