@@ -298,7 +298,7 @@ impl Client {
298
298
// Active servers will have a writer and a reader
299
299
self . conns
300
300
. lock ( )
301
- . unwrap ( )
301
+ . expect ( "All lock holders should not panic" )
302
302
. active_servers ( )
303
303
. map ( |hostname| hostname. clone ( ) )
304
304
. collect ( )
@@ -522,19 +522,23 @@ impl Client {
522
522
/// Returns an error if there aren't any connected servers, or no ECHO_RES comes back
523
523
pub async fn echo ( & mut self , payload : & [ u8 ] ) -> Result < ( ) , io:: Error > {
524
524
let packet = new_req ( ECHO_REQ , Bytes :: copy_from_slice ( payload) ) ;
525
- if self . conns . lock ( ) . unwrap ( ) . len ( ) < 1 {
526
- return Err ( io:: Error :: new (
527
- io:: ErrorKind :: Other ,
528
- "No connections for echo!" ,
529
- ) ) ;
530
- }
531
- self . conns
532
- . lock ( )
533
- . unwrap ( )
534
- . get ( 0 )
535
- . unwrap ( )
536
- . send_packet ( packet)
537
- . await ?;
525
+ {
526
+ let conns = self
527
+ . conns
528
+ . lock ( )
529
+ . expect ( "All lock holders should not panic" ) ;
530
+ if conns. len ( ) < 1 {
531
+ return Err ( io:: Error :: new (
532
+ io:: ErrorKind :: Other ,
533
+ "No connections for echo!" ,
534
+ ) ) ;
535
+ }
536
+ conns
537
+ . get ( 0 )
538
+ . expect ( "Conns is locked by mutex and we checked length above" )
539
+ . send_packet ( packet)
540
+ . await ?;
541
+ } // Unlock conns
538
542
debug ! ( "Waiting for echo response" ) ;
539
543
match self . client_data . receivers ( ) . echo_rx . recv ( ) . await {
540
544
Some ( res) => info ! ( "echo received: {:?}" , res) ,
@@ -607,7 +611,10 @@ impl Client {
607
611
data. extend ( payload) ;
608
612
let packet = new_req ( ptype, data. freeze ( ) ) ;
609
613
{
610
- let mut conns = self . conns . lock ( ) . unwrap ( ) ;
614
+ let mut conns = self
615
+ . conns
616
+ . lock ( )
617
+ . expect ( "All lock holders should not panic" ) ;
611
618
let conn = match conns. get_hashed_conn ( & unique. iter ( ) . map ( |b| * b) . collect ( ) ) {
612
619
None => {
613
620
return Err ( io:: Error :: new (
@@ -640,9 +647,14 @@ impl Client {
640
647
641
648
/// Sends a GET_STATUS packet and then returns the STATUS_RES in a [JobStatus]
642
649
pub async fn get_status ( & mut self , handle : & ServerHandle ) -> Result < JobStatus , io:: Error > {
643
- // TODO: mapping?
650
+ let mut payload = BytesMut :: with_capacity ( handle. handle ( ) . len ( ) ) ;
651
+ payload. extend ( handle. handle ( ) ) ;
652
+ let status_req = new_req ( GET_STATUS , payload. freeze ( ) ) ;
644
653
{
645
- let conns = self . conns . lock ( ) . unwrap ( ) ;
654
+ let conns = self
655
+ . conns
656
+ . lock ( )
657
+ . expect ( "All lock holders should not panic" ) ;
646
658
let conn = match conns. get_by_server ( handle. server ( ) ) . and_then ( |conn| {
647
659
if conn. is_active ( ) {
648
660
Some ( conn)
@@ -653,9 +665,6 @@ impl Client {
653
665
None => return Err ( io:: Error :: new ( ErrorKind :: Other , "No connection for job" ) ) ,
654
666
Some ( conn) => conn,
655
667
} ;
656
- let mut payload = BytesMut :: with_capacity ( handle. handle ( ) . len ( ) ) ;
657
- payload. extend ( handle. handle ( ) ) ;
658
- let status_req = new_req ( GET_STATUS , payload. freeze ( ) ) ;
659
668
conn. send_packet ( status_req) . await ?;
660
669
}
661
670
debug ! ( "Waiting for STATUS_RES for {}" , handle) ;
0 commit comments