Skip to content

Commit 69bb595

Browse files
authored
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.
1 parent 3abb186 commit 69bb595

File tree

1 file changed

+12
-1
lines changed
  • sqlx-macros-core/src/database

1 file changed

+12
-1
lines changed

sqlx-macros-core/src/database/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,19 @@ impl<DB: DatabaseExt> CachingDescribeBlocking<DB> {
8888
}
8989
};
9090

91-
conn.describe(AssertSqlSafe(query.to_string()).into_sql_str())
91+
match conn
92+
.describe(AssertSqlSafe(query.to_string()).into_sql_str())
9293
.await
94+
{
95+
Ok(describe) => Ok(describe),
96+
Err(e) => {
97+
if matches!(e, sqlx_core::Error::Io(_) | sqlx_core::Error::Protocol(_)) {
98+
cache.remove(database_url);
99+
}
100+
101+
Err(e)
102+
}
103+
}
93104
})
94105
}
95106
}

0 commit comments

Comments
 (0)