Skip to content

Commit 20f0aae

Browse files
committed
fix: properly announce connection closure during error
1 parent 394851e commit 20f0aae

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

tokio-postgres/src/connection.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,7 @@ where
318318
self.parameters.get(name).map(|s| &**s)
319319
}
320320

321-
/// Polls for asynchronous messages from the server.
322-
///
323-
/// The server can send notices as well as notifications asynchronously to the client. Applications that wish to
324-
/// examine those messages should use this method to drive the connection rather than its `Future` implementation.
325-
///
326-
/// Return values of `None` or `Some(Err(_))` are "terminal"; callers should not invoke this method again after
327-
/// receiving one of those values.
328-
pub fn poll_message(
321+
fn poll_message_inner(
329322
&mut self,
330323
cx: &mut Context<'_>,
331324
) -> Poll<Option<Result<AsyncMessage, Error>>> {
@@ -343,6 +336,26 @@ where
343336
},
344337
}
345338
}
339+
340+
/// Polls for asynchronous messages from the server.
341+
///
342+
/// The server can send notices as well as notifications asynchronously to the client. Applications that wish to
343+
/// examine those messages should use this method to drive the connection rather than its `Future` implementation.
344+
///
345+
/// Return values of `None` or `Some(Err(_))` are "terminal"; callers should not invoke this method again after
346+
/// receiving one of those values.
347+
pub fn poll_message(
348+
&mut self,
349+
cx: &mut Context<'_>,
350+
) -> Poll<Option<Result<AsyncMessage, Error>>> {
351+
match self.poll_message_inner(cx) {
352+
nominal @ (Poll::Pending | Poll::Ready(Some(Ok(_)))) => nominal,
353+
terminal @ (Poll::Ready(None) | Poll::Ready(Some(Err(_)))) => {
354+
self.receiver.close();
355+
terminal
356+
}
357+
}
358+
}
346359
}
347360

348361
impl<S, T> Future for Connection<S, T>

0 commit comments

Comments
 (0)