From 04f1ad17d85d9108adc179998a3f983ae53ee8e8 Mon Sep 17 00:00:00 2001 From: Peter Hamilton Date: Sat, 5 Aug 2023 13:29:51 -0700 Subject: [PATCH] Make PgListener recover from UnexpectedEof This is often encountered when the host the db is on is restarted. For example, a reboot of AWS Aurora cauases 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 e09f4c5203..242823688f 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;