Skip to content

Commit

Permalink
Handle interrupted error in network read thread
Browse files Browse the repository at this point in the history
  • Loading branch information
maximecb committed Nov 11, 2023
1 parent 38af645 commit 19d3f29
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions vm/src/sys/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::{HashMap, VecDeque};
use std::slice;
use std::thread;
use std::net::{TcpListener, TcpStream};
use std::io::{self, Read, Write};
use std::io::{self, Read, Write, Error};
use std::sync::{Arc, Weak, Mutex};
use crate::vm::{VM, Value, ExitReason};

Expand Down Expand Up @@ -78,7 +78,7 @@ fn listen_thread(
incoming.push_back(stream);
}

// Socket closed
// Socket has been closed, stop
_ => {
break;
}
Expand Down Expand Up @@ -156,7 +156,7 @@ fn read_thread(
let mut buf: [u8; 16384] = [0; 16384];

match stream.read(&mut buf) {
// End of file, connection closed
// End of file, connection closed, stop
Ok(0) => {
break;
}
Expand Down Expand Up @@ -186,6 +186,14 @@ fn read_thread(
}
}

// This error indicates blocking read stopped,
// but it can be retried
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {
continue;
}

// Most errors are the result of a lost connection
// Stop the read thread
Err(e) => {
println!("error in read thread: {e}");
break
Expand Down

0 comments on commit 19d3f29

Please sign in to comment.