Workaround hyper panic

This commit is contained in:
arkpar 2016-06-30 10:07:33 +02:00
parent af65945b58
commit 51c6b85f80

View File

@ -43,9 +43,7 @@ impl WorkPoster {
} }
} }
}).collect(); }).collect();
let client = Client::<PostHandler>::configure() let client = WorkPoster::create_client();
.keep_alive(false)
.build().expect("Error creating HTTP client");
WorkPoster { WorkPoster {
client: Mutex::new(client), client: Mutex::new(client),
urls: urls, urls: urls,
@ -53,6 +51,13 @@ impl WorkPoster {
} }
} }
fn create_client() -> Client<PostHandler> {
let client = Client::<PostHandler>::configure()
.keep_alive(true)
.build().expect("Error creating HTTP client") as Client<PostHandler>;
client
}
pub fn notify(&self, pow_hash: H256, difficulty: U256, number: u64) { pub fn notify(&self, pow_hash: H256, difficulty: U256, number: u64) {
// TODO: move this to engine // TODO: move this to engine
let target = Ethash::difficulty_to_boundary(&difficulty); let target = Ethash::difficulty_to_boundary(&difficulty);
@ -60,14 +65,19 @@ impl WorkPoster {
let seed_hash = H256::from_slice(&seed_hash[..]); let seed_hash = H256::from_slice(&seed_hash[..]);
let body = format!(r#"{{ "result": ["0x{}","0x{}","0x{}","0x{:x}"] }}"#, let body = format!(r#"{{ "result": ["0x{}","0x{}","0x{}","0x{:x}"] }}"#,
pow_hash.hex(), seed_hash.hex(), target.hex(), number); 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 { for u in &self.urls {
if let Err(e) = client.request(u.clone(), PostHandler { body: body.clone() }) {
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() }) { 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 {} : {}", u, e);
} }
} }
} }
} }
}
struct PostHandler { struct PostHandler {
body: String, body: String,