Commit ca56d311 authored by Daniel García Moreno's avatar Daniel García Moreno

api: Wait when sync error to avoid 100% usage

When there's no connection multiple calls to sync makes the Fractal process to consume all the CPU because the long polling timeout isn't working so we need to wait here to avoid this problem. Fix #139
parent 57d64410
use globals;
use std::thread;
use std::{thread, time};
use error::Error;
use util::json_q;
use util::get_rooms_from_json;
......@@ -133,7 +133,14 @@ pub fn sync(bk: &Backend) -> Result<(), Error> {
tx.send(BKResponse::Sync(next_batch.clone())).unwrap();
data.lock().unwrap().since = next_batch;
},
Err(err) => { tx.send(BKResponse::SyncError(err)).unwrap() }
Err(err) => {
// we wait if there's an error to avoid 100% CPU
eprintln!("Sync Error, waiting 10 seconds to respond for the next sync");
let ten_seconds = time::Duration::from_millis(10000);
thread::sleep(ten_seconds);
tx.send(BKResponse::SyncError(err)).unwrap();
}
};
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment