unwind panics instead of aborting the process
a panic in a session task now kills that connection, tokio catches it and the accept loop carries on. with abort it took the whole server down. the data table RwLock is std so it poisons on panic, and every lookup went through expect(). one panic would have bricked every later table read, which is worse than the abort was. it reads the inner value now, the table is read only once installed.
This commit is contained in:
parent
ca8e41c2c5
commit
e43f3fc02c
2 changed files with 8 additions and 5 deletions
|
|
@ -37,5 +37,4 @@ syn = { version = "2", features = ["full", "extra-traits"] }
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
lto = "thin"
|
lto = "thin"
|
||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
panic = "abort"
|
|
||||||
strip = true
|
strip = true
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::{Arc, OnceLock, RwLock};
|
use std::sync::{Arc, OnceLock, PoisonError, RwLock};
|
||||||
use titan::{CsvError, CsvReader, GlobalId};
|
use titan::{CsvError, CsvReader, GlobalId};
|
||||||
use crate::data::logic_data::LogicData;
|
use crate::data::logic_data::LogicData;
|
||||||
use crate::data::logic_data_table::LogicDataTable;
|
use crate::data::logic_data_table::LogicDataTable;
|
||||||
|
|
@ -110,11 +110,15 @@ impl LogicDataTables {
|
||||||
Self::default()
|
Self::default()
|
||||||
}
|
}
|
||||||
pub fn install(tables: Arc<LogicDataTables>) -> bool {
|
pub fn install(tables: Arc<LogicDataTables>) -> bool {
|
||||||
let mut slot = INSTANCE.write().expect("data table lock poisoned");
|
let mut slot = INSTANCE.write().unwrap_or_else(PoisonError::into_inner);
|
||||||
slot.replace(tables).is_none()
|
slot.replace(tables).is_none()
|
||||||
}
|
}
|
||||||
pub fn instance() -> Arc<LogicDataTables> {
|
pub fn instance() -> Arc<LogicDataTables> {
|
||||||
match INSTANCE.read().expect("data table lock poisoned").as_ref() {
|
match INSTANCE
|
||||||
|
.read()
|
||||||
|
.unwrap_or_else(PoisonError::into_inner)
|
||||||
|
.as_ref()
|
||||||
|
{
|
||||||
Some(tables) => Arc::clone(tables),
|
Some(tables) => Arc::clone(tables),
|
||||||
None => Arc::clone(EMPTY.get_or_init(|| Arc::new(LogicDataTables::empty()))),
|
None => Arc::clone(EMPTY.get_or_init(|| Arc::new(LogicDataTables::empty()))),
|
||||||
}
|
}
|
||||||
|
|
@ -122,7 +126,7 @@ impl LogicDataTables {
|
||||||
pub fn is_installed() -> bool {
|
pub fn is_installed() -> bool {
|
||||||
INSTANCE
|
INSTANCE
|
||||||
.read()
|
.read()
|
||||||
.expect("data table lock poisoned")
|
.unwrap_or_else(PoisonError::into_inner)
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|tables| tables.is_loaded())
|
.map(|tables| tables.is_loaded())
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue