Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

catch the panic to avoid peer thread quit early #2686

Merged
merged 6 commits into from
Mar 23, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions chain/src/txhashset/txhashset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use grin_store;
use grin_store::pmmr::{PMMRBackend, PMMR_FILES};
use std::collections::HashSet;
use std::fs::{self, File};
use std::panic;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::{Instant, SystemTime, UNIX_EPOCH};
Expand Down Expand Up @@ -1456,8 +1457,31 @@ pub fn zip_write(
) -> Result<(), Error> {
let txhashset_path = Path::new(&root_dir).join(TXHASHSET_SUBDIR);
fs::create_dir_all(txhashset_path.clone())?;
zip::decompress(txhashset_data, &txhashset_path, expected_file)
.map_err(|ze| ErrorKind::Other(ze.to_string()))?;

// catch the panic to avoid the thread quit
{
panic::set_hook(Box::new(|_info| {
// do nothing
}));
let result = panic::catch_unwind(|| {
garyyu marked this conversation as resolved.
Show resolved Hide resolved
zip::decompress(txhashset_data, &txhashset_path, expected_file)
.map_err(|ze| ErrorKind::Other(ze.to_string()))
});
match result {
Ok(res) => {
if let Err(e) = res {
return Err(e.into());
}
}
Err(_) => {
error!("caught panic on zip::decompress!");
return Err(
ErrorKind::InvalidTxHashSet("panic on zip::decompress".to_owned()).into(),
);
}
}
}

check_and_remove_files(&txhashset_path, header)
}

Expand Down