Skip to content

Commit

Permalink
fix panic when tcp connect goes away before handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bluejekyll authored and djc committed Mar 28, 2022
1 parent b470913 commit 4743835
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions crates/server/src/server/server_future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ impl<T: RequestHandler> ServerFuture<T> {
async move {
loop {
let tcp_stream = listener.accept().await;
let tcp_stream = match tcp_stream {
Ok((t, _)) => t,
let (tcp_stream, src_addr) = match tcp_stream {
Ok((t, s)) => (t, s),
Err(e) => {
debug!("error receiving TCP tcp_stream error: {}", e);
continue;
Expand All @@ -129,7 +129,6 @@ impl<T: RequestHandler> ServerFuture<T> {

// and spawn to the io_loop
tokio::spawn(async move {
let src_addr = tcp_stream.peer_addr().unwrap();
debug!("accepted request from: {}", src_addr);
// take the created stream...
let (buf_stream, stream_handle) =
Expand Down Expand Up @@ -229,8 +228,8 @@ impl<T: RequestHandler> ServerFuture<T> {
async move {
loop {
let tcp_stream = listener.accept().await;
let tcp_stream = match tcp_stream {
Ok((t, _)) => t,
let (tcp_stream, src_addr) = match tcp_stream {
Ok((t, s)) => (t, s),
Err(e) => {
debug!("error receiving TLS tcp_stream error: {}", e);
continue;
Expand All @@ -242,7 +241,6 @@ impl<T: RequestHandler> ServerFuture<T> {

// kick out to a different task immediately, let them do the TLS handshake
tokio::spawn(async move {
let src_addr = tcp_stream.peer_addr().unwrap();
debug!("starting TLS request from: {}", src_addr);

// perform the TLS
Expand Down Expand Up @@ -371,8 +369,8 @@ impl<T: RequestHandler> ServerFuture<T> {
async move {
loop {
let tcp_stream = listener.accept().await;
let tcp_stream = match tcp_stream {
Ok((t, _)) => t,
let (tcp_stream, src_addr) = match tcp_stream {
Ok((t, s)) => (t, s),
Err(e) => {
debug!("error receiving TLS tcp_stream error: {}", e);
continue;
Expand All @@ -384,7 +382,6 @@ impl<T: RequestHandler> ServerFuture<T> {

// kick out to a different task immediately, let them do the TLS handshake
tokio::spawn(async move {
let src_addr = tcp_stream.peer_addr().unwrap();
debug!("starting TLS request from: {}", src_addr);

// perform the TLS
Expand Down Expand Up @@ -513,8 +510,8 @@ impl<T: RequestHandler> ServerFuture<T> {
let dns_hostname = dns_hostname;
loop {
let tcp_stream = listener.accept().await;
let tcp_stream = match tcp_stream {
Ok((t, _)) => t,
let (tcp_stream, src_addr) = match tcp_stream {
Ok((t, s)) => (t, s),
Err(e) => {
debug!("error receiving HTTPS tcp_stream error: {}", e);
continue;
Expand All @@ -526,7 +523,6 @@ impl<T: RequestHandler> ServerFuture<T> {
let dns_hostname = dns_hostname.clone();

tokio::spawn(async move {
let src_addr = tcp_stream.peer_addr().unwrap();
debug!("starting HTTPS request from: {}", src_addr);

// TODO: need to consider timeout of total connect...
Expand Down

0 comments on commit 4743835

Please sign in to comment.