diff --git a/ethcore/src/miner/work_notify.rs b/ethcore/src/miner/work_notify.rs index 6144e2d3d..a153be79f 100644 --- a/ethcore/src/miner/work_notify.rs +++ b/ethcore/src/miner/work_notify.rs @@ -43,9 +43,7 @@ impl WorkPoster { } } }).collect(); - let client = Client::::configure() - .keep_alive(false) - .build().expect("Error creating HTTP client"); + let client = WorkPoster::create_client(); WorkPoster { client: Mutex::new(client), urls: urls, @@ -53,6 +51,13 @@ impl WorkPoster { } } + fn create_client() -> Client { + let client = Client::::configure() + .keep_alive(true) + .build().expect("Error creating HTTP client") as Client; + client + } + pub fn notify(&self, pow_hash: H256, difficulty: U256, number: u64) { // TODO: move this to engine let target = Ethash::difficulty_to_boundary(&difficulty); @@ -60,10 +65,15 @@ impl WorkPoster { let seed_hash = H256::from_slice(&seed_hash[..]); let body = format!(r#"{{ "result": ["0x{}","0x{}","0x{}","0x{:x}"] }}"#, pow_hash.hex(), seed_hash.hex(), target.hex(), number); - let client = self.client.lock().unwrap(); + let mut client = self.client.lock().unwrap(); for u in &self.urls { if let Err(e) = client.request(u.clone(), PostHandler { body: body.clone() }) { - warn!("Error sending HTTP notification to {} : {}", u, e); + warn!("Error sending HTTP notification to {} : {}, retrying", u, e); + // TODO: remove this once https://github.com/hyperium/hyper/issues/848 is fixed + *client = WorkPoster::create_client(); + if let Err(e) = client.request(u.clone(), PostHandler { body: body.clone() }) { + warn!("Error sending HTTP notification to {} : {}", u, e); + } } } }