Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

riverpgxv5: hijack raw listener conn to assume control #661

Merged
merged 1 commit into from
Oct 30, 2024

Conversation

bgentry
Copy link
Contributor

@bgentry bgentry commented Oct 29, 2024

The previous implementation of the driver would Acquire() a conn from the pgxpool.Pool, but keep the pool in control of the conn. This meant that the pool would still do its regular maintenance checks on the conn, such as closing it after it had reached its max lifetime.

This isn't actually desirable in the case of a LISTEN listener—we want the listener to stay alive as long as possible and to avoid missing any notifications. We perform our own health checks on the conn in the form of periodic pings, which should be sufficient to make sure the conn is still connected and functioning properly.

As such, adjust the driver so that it calls Hijack() on the conn immediately after acquiring it, assuming full control of it from the underlying pool. The listener is still responsible for closing the conn at shutdown.

Fixes #660.

@bgentry bgentry requested a review from brandur October 29, 2024 14:39
The previous implementation of the driver would `Acquire()` a conn from
the `pgxpool.Pool`, but keep the pool in control of the conn. This meant
that the pool would still do its regular maintenance checks on the conn,
such as closing it after it had reached its max lifetime.

This isn't actually desirable in the case of a `LISTEN` listener—we want
the listener to stay alive as long as possible and to avoid missing any
notifications. We perform our own health checks on the conn in the form
of periodic pings, which should be sufficient to make sure the conn is
still connected and functioning properly.

As such, adjust the driver so that it calls `Hijack()` on the conn
immediately after acquiring it, assuming full control of it from the
underlying pool. The listener is still responsible for closing the conn
at shutdown.

Fixes #660.
@bgentry bgentry force-pushed the bg-hijack-listener-conn branch from c3f1b83 to a4944da Compare October 29, 2024 14:39
@bgentry bgentry merged commit fb9bad6 into master Oct 30, 2024
14 checks passed
@bgentry bgentry deleted the bg-hijack-listener-conn branch October 30, 2024 14:15
tigrato pushed a commit to gravitational/river that referenced this pull request Dec 18, 2024
The previous implementation of the driver would `Acquire()` a conn from
the `pgxpool.Pool`, but keep the pool in control of the conn. This meant
that the pool would still do its regular maintenance checks on the conn,
such as closing it after it had reached its max lifetime.

This isn't actually desirable in the case of a `LISTEN` listener—we want
the listener to stay alive as long as possible and to avoid missing any
notifications. We perform our own health checks on the conn in the form
of periodic pings, which should be sufficient to make sure the conn is
still connected and functioning properly.

As such, adjust the driver so that it calls `Hijack()` on the conn
immediately after acquiring it, assuming full control of it from the
underlying pool. The listener is still responsible for closing the conn
at shutdown.

Fixes riverqueue#660.
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.

1 participant