Skip to content

Commit

Permalink
Make PgListener recover from UnexpectedEof
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 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.
  • Loading branch information
hamiltop authored and rex-remind101 committed Sep 29, 2023
1 parent e80291b commit 04f1ad1
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 04f1ad1

Please sign in to comment.