Skip to content

Commit ce733a8

Browse files
authored
update timeout (#159)
1 parent 896a6a8 commit ce733a8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/transport.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ mod recorder;
2626
const MIN_SERVER_VERSION: i32 = 100;
2727
const MAX_SERVER_VERSION: i32 = server_versions::HISTORICAL_SCHEDULE;
2828
const MAX_RETRIES: i32 = 20;
29-
const TWS_READ_TIMEOUT: Duration = Duration::from_secs(3);
29+
const TWS_READ_TIMEOUT: Duration = Duration::from_secs(1);
3030

3131
pub(crate) trait MessageBus: Send + Sync {
3232
// Sends formatted message to TWS and creates a reply channel by request id.
@@ -220,21 +220,22 @@ impl TcpMessageBus {
220220
fn start_dispatcher_thread(self: &Arc<Self>, server_version: i32) -> JoinHandle<()> {
221221
let message_bus = Arc::clone(self);
222222

223-
const RECONNECT_ERRORS: &[ErrorKind] = &[ErrorKind::ConnectionReset, ErrorKind::ConnectionAborted, ErrorKind::UnexpectedEof];
223+
const RECONNECT_CODES: &[ErrorKind] = &[ErrorKind::ConnectionReset, ErrorKind::ConnectionAborted, ErrorKind::UnexpectedEof];
224+
const TIMEOUT_CODES: &[ErrorKind] = &[ErrorKind::WouldBlock, ErrorKind::TimedOut];
224225

225226
thread::spawn(move || {
226227
loop {
227228
match message_bus.read_message() {
228229
Ok(message) => {
229230
message_bus.dispatch_message(server_version, message);
230231
}
231-
Err(Error::Io(e)) if e.kind() == ErrorKind::WouldBlock => {
232+
Err(Error::Io(e)) if TIMEOUT_CODES.contains(&e.kind()) => {
232233
if message_bus.is_shutting_down() {
233234
debug!("dispatcher thread exiting");
234235
return;
235236
}
236237
}
237-
Err(Error::Io(e)) if RECONNECT_ERRORS.contains(&e.kind()) => {
238+
Err(Error::Io(e)) if RECONNECT_CODES.contains(&e.kind()) => {
238239
error!("error reading next message (will attempt reconnect): {:?}", e);
239240

240241
// Attempt to reconnect to TWS.

0 commit comments

Comments
 (0)