Skip to content

Commit

Permalink
Make PgListener recover from UnexpectedEof (#2684)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hamiltop authored Oct 17, 2023
1 parent b85b723 commit ab0d10d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sqlx-postgres/src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit ab0d10d

Please sign in to comment.