From ab0d10d935d6794817b851fb08fcbf371447b5a8 Mon Sep 17 00:00:00 2001 From: Peter Hamilton Date: Tue, 17 Oct 2023 16:10:53 -0700 Subject: [PATCH] Make PgListener recover from UnexpectedEof (#2684) This is often encountered when the host the db is on is restarted. For example, a reboot of AWS Aurora causes this. If we don't handle this properly the PgListeners are stuck in an erroring state, even when the DB is back online. By catching it here, we will reconnect when it is (eventually) back online. --- sqlx-postgres/src/listener.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sqlx-postgres/src/listener.rs b/sqlx-postgres/src/listener.rs index e09f4c52..24282368 100644 --- a/sqlx-postgres/src/listener.rs +++ b/sqlx-postgres/src/listener.rs @@ -262,7 +262,10 @@ impl PgListener { // The connection is dead, ensure that it is dropped, // update self state, and loop to try again. - Err(Error::Io(err)) if err.kind() == io::ErrorKind::ConnectionAborted => { + Err(Error::Io(err)) + if (err.kind() == io::ErrorKind::ConnectionAborted + || err.kind() == io::ErrorKind::UnexpectedEof) => + { self.buffer_tx = self.connection().await?.stream.notifications.take(); self.connection = None;