@@ -4,6 +4,7 @@ use crate::{
44 ToStatement , Transaction , TransactionBuilder ,
55} ;
66use std:: task:: Poll ;
7+ use std:: time:: Duration ;
78use tokio_postgres:: tls:: { MakeTlsConnect , TlsConnect } ;
89use tokio_postgres:: types:: { BorrowToSql , ToSql , Type } ;
910use tokio_postgres:: { Error , Row , SimpleQueryMessage , Socket } ;
@@ -414,8 +415,14 @@ impl Client {
414415 }
415416
416417 /// Validates connection, timing out after specified duration.
417- pub fn is_valid ( & mut self , timeout : std:: time:: Duration ) -> Result < ( ) , Error > {
418- self . connection . block_on ( self . client . is_valid ( timeout) )
418+ pub fn is_valid ( & mut self , timeout : Duration ) -> Result < ( ) , Error > {
419+ let is_valid = Client :: is_valid_inner ( & self . client , timeout) ;
420+ self . connection . block_on ( is_valid)
421+ }
422+
423+ async fn is_valid_inner ( client : & tokio_postgres:: Client , timeout : Duration ) -> Result < ( ) , Error > {
424+ let trivial_query = client. simple_query ( "" ) ;
425+ tokio:: time:: timeout ( timeout, trivial_query) . await ?. map ( |_| ( ) )
419426 }
420427
421428 /// Executes a sequence of SQL statements using the simple query protocol.
0 commit comments