mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-12-28 19:49:23 +00:00
Drop cached db connections in macros upon hitting an error (#4009)
Once a connection to the database is lost all future macro evaluations will fail. This is fine for normal compilation since it tends to be short but causes issues with rust-analyzer since it keeps the macro binaries loaded for a long time. This commit changes the macro implementation to drop the cached connection when it encounters an IO or protocol error. In practice these seem to be the errors that show up when the connection is lost and dumping the connection on every error would have unnecessary overhead.
This commit is contained in:
parent
3abb186324
commit
69bb5952ab
@ -88,8 +88,19 @@ impl<DB: DatabaseExt> CachingDescribeBlocking<DB> {
|
||||
}
|
||||
};
|
||||
|
||||
conn.describe(AssertSqlSafe(query.to_string()).into_sql_str())
|
||||
match conn
|
||||
.describe(AssertSqlSafe(query.to_string()).into_sql_str())
|
||||
.await
|
||||
{
|
||||
Ok(describe) => Ok(describe),
|
||||
Err(e) => {
|
||||
if matches!(e, sqlx_core::Error::Io(_) | sqlx_core::Error::Protocol(_)) {
|
||||
cache.remove(database_url);
|
||||
}
|
||||
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user