From 42d876bf41c1572fbc961cca53d9b63e7d76e23b Mon Sep 17 00:00:00 2001 From: Tim Kuehn Date: Thu, 11 Feb 2016 21:57:58 -0800 Subject: [PATCH] Don't panic if on Err from try_clone --- tarpc/src/protocol/server.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tarpc/src/protocol/server.rs b/tarpc/src/protocol/server.rs index 68505f8..6d39f7d 100644 --- a/tarpc/src/protocol/server.rs +++ b/tarpc/src/protocol/server.rs @@ -27,8 +27,7 @@ struct ConnectionHandler<'a, S> impl<'a, S> ConnectionHandler<'a, S> where S: Serve { - fn handle_conn<'b>(&'b mut self, scope: &Scope<'b>) -> Result<()> - { + fn handle_conn<'b>(&'b mut self, scope: &Scope<'b>) -> Result<()> { let ConnectionHandler { ref mut read_stream, ref mut write_stream, @@ -48,7 +47,7 @@ impl<'a, S> ConnectionHandler<'a, S> rpc_id: rpc_id, message: reply }; - tx.send(reply_packet).unwrap(); + tx.send(reply_packet).expect(pos!()); }); if shutdown.load(Ordering::SeqCst) { info!("ConnectionHandler: server shutdown, so closing connection."); @@ -161,7 +160,7 @@ impl<'a, S: 'a> Server<'a, S> return; } Err(TryRecvError::Disconnected) => { - info!("serve: sender disconnected."); + info!("serve: shutdown sender disconnected."); return; } _ => (), @@ -175,10 +174,19 @@ impl<'a, S: 'a> Server<'a, S> }; if let Err(err) = conn.set_read_timeout(self.read_timeout) { info!("serve: could not set read timeout: {:?}", err); - return; + continue; } + let read_conn = match conn.try_clone() { + Err(err) => { + error!("serve: could not clone tcp stream; possibly out of file descriptors? \ + Err: {:?}", + err); + continue; + } + Ok(conn) => conn, + }; let mut handler = ConnectionHandler { - read_stream: BufReader::new(conn.try_clone().unwrap()), + read_stream: BufReader::new(read_conn), write_stream: BufWriter::new(conn), server: self.server, shutdown: self.shutdown,