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

Handle dynamic program dlopen failures gracefully #1496

Merged
merged 2 commits into from
Oct 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ impl Bank {
let mut last_ids_q = self.last_ids_q.write().unwrap();
if last_ids_q.last_ids.len() >= MAX_ENTRY_IDS {
let id = last_ids_q.last_ids.pop_front().unwrap();
info!("removing last_id {}", id);
debug!("removing last_id {}", id);
last_ids_q.last_ids_sigs.remove(&id);
}
inc_new_counter_info!("bank-register_entry_id-registered", 1);
Expand Down
7 changes: 4 additions & 3 deletions src/dynamic_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use libc;
use libloading::os::unix::*;
#[cfg(windows)]
use libloading::os::windows::*;
use result::Result;

use solana_program_interface::account::KeyedAccount;
use solana_program_interface::pubkey::Pubkey;
Expand Down Expand Up @@ -80,12 +81,12 @@ pub enum DynamicProgram {
}

impl DynamicProgram {
pub fn new_native(name: String) -> Self {
pub fn new_native(name: String) -> Result<Self> {
// create native program
let path = ProgramPath::Native {}.create(&name);
// TODO linux tls bug can cause crash on dlclose, workaround by never unloading
let library = Library::open(Some(path), libc::RTLD_NODELETE | libc::RTLD_NOW).unwrap();
DynamicProgram::Native { name, library }
let library = Library::open(Some(path), libc::RTLD_NODELETE | libc::RTLD_NOW)?;
Ok(DynamicProgram::Native { name, library })
}

pub fn new_bpf_from_file(name: String) -> Self {
Expand Down
8 changes: 7 additions & 1 deletion src/system_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ impl SystemProgram {
}
SystemProgram::Load { program_id, name } => {
let mut hashmap = loaded_programs.write().unwrap();
hashmap.insert(program_id, DynamicProgram::new_native(name));
hashmap.insert(
program_id,
DynamicProgram::new_native(name).map_err(|err| {
warn!("SystemProgram::Load failure: {:?}", err);
Error::InvalidArgument
})?,
);
}
}
Ok(())
Expand Down
8 changes: 4 additions & 4 deletions tests/programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ fn test_native_file_noop() {
.map(|(key, account)| KeyedAccount { key, account })
.collect();

let dp = DynamicProgram::new_native("noop".to_string());
let dp = DynamicProgram::new_native("noop".to_string()).unwrap();
dp.call(&mut infos, &data);
}
}
Expand All @@ -163,7 +163,7 @@ fn test_native_file_move_funds_success() {
.map(|(key, account)| KeyedAccount { key, account })
.collect();

let dp = DynamicProgram::new_native("move_funds".to_string());
let dp = DynamicProgram::new_native("move_funds".to_string()).unwrap();
dp.call(&mut infos, &data);
}
assert_eq!(0, accounts[0].tokens);
Expand All @@ -186,7 +186,7 @@ fn test_native_file_move_funds_insufficient_funds() {
.map(|(key, account)| KeyedAccount { key, account })
.collect();

let dp = DynamicProgram::new_native("move_funds".to_string());
let dp = DynamicProgram::new_native("move_funds".to_string()).unwrap();
dp.call(&mut infos, &data);
}
assert_eq!(10, accounts[0].tokens);
Expand Down Expand Up @@ -216,7 +216,7 @@ fn test_program_native_move_funds_succes_many_threads() {
.map(|(key, account)| KeyedAccount { key, account })
.collect();

let dp = DynamicProgram::new_native("move_funds".to_string());
let dp = DynamicProgram::new_native("move_funds".to_string()).unwrap();
dp.call(&mut infos, &data);
}
assert_eq!(0, accounts[0].tokens);
Expand Down