Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pgdog/src/backend/pool/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ impl Connection {
///
pub(crate) async fn read(&mut self) -> Result<Message, Error> {
select! {
notification = self.pub_sub.recv() => {
// If we're listening on a NOTIFY channel, wait for a message, and if
// one is available, then we return it here.
notification = self.pub_sub.recv(), if self.pub_sub.is_listening() => {
Ok(notification.ok_or_else(|| Error::ProtocolOutOfSync)?.message())
}

Expand Down
8 changes: 8 additions & 0 deletions pgdog/src/backend/pub_sub/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ impl PubSubClient {
}
}

// Do we have an active `listen` on anything
// This is solely used to determine if we should have an extra select! branch
// within our `read()` method. If we're not listening on anything,
// no point in adding the extra overhead within the branch.
pub(crate) fn is_listening(&self) -> bool {
!self.unlisten.is_empty()
}

/// Listen on a channel.
pub(crate) fn listen(&mut self, channel: &str, mut rx: Listener) {
let tx = self.tx.clone();
Expand Down
Loading