Skip to content

Conversation

@swlynch99
Copy link
Contributor

When PgListener's underlying connection is closed, try_recv() will return Ok(None) and reconnect on the next call. In this case, user code is supposed to reload its state from the database (or otherwise handle potentially missing messages). However, if the user code uses another database connection to do so then there is a period between when the state is reloaded and PgListener's connection is re-established where notifications are lost without any indication that this has happened.

This commit changes PgListener to eagerly reconnect by default. At the suggestion of @abonander on discord, I have also included an option to switch back to the old behaviour in the case where someone was depending on it.

Now, if the connection is closed then, by default, user code can do whatever it needs to do in order to recover and any notifications emitted in the meantime will be waiting for it when it is done.

I have defaulted eager_connect to true since I think the current behaviour is a bit of a footgun but if you think that is too big of a change then I can change it to false.

When PgListener's underlying connection is closed, try_recv() will
return Ok(None) and reconnect on the next call. In this case, user code
is supposed to reload its state from the database (or otherwise handle
potentially missing messages). However, if the user code uses another
database connection to do so then there is a period between when the
state is reloaded and PgListener's connection is re-established where
notifications are lost without any indication that this has happened.

This commit changes PgListener to eagerly reconnect by default. At the
suggestion of @abonander on discord, I have also included an option to
switch back to the old behaviour in the case where someone was depending
on it.

Now, if the connection is closed then, by default, user code can do
whatever it needs to do in order to recover and any notifications
emitted in the meantime will be waiting for it when it is done.
@swlynch99 swlynch99 force-pushed the pglistener-eager-reconnect branch from ed49eef to d782e42 Compare November 27, 2024 20:50
@swlynch99
Copy link
Contributor Author

Formatting should be fixed now. That was the only CI job that failed.

@abonander abonander merged commit 503a72c into launchbadge:main Nov 27, 2024
81 checks passed
@swlynch99 swlynch99 deleted the pglistener-eager-reconnect branch November 27, 2024 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants