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:
WiseDev 2026-08-23 09:42:44 +03:00
parent ca8e41c2c5
commit e43f3fc02c
2 changed files with 8 additions and 5 deletions

View file

@ -37,5 +37,4 @@ syn = { version = "2", features = ["full", "extra-traits"] }
opt-level = 3
lto = "thin"
codegen-units = 1
panic = "abort"
strip = true

View file

@ -1,6 +1,6 @@
use std::collections::HashMap;
use std::path::Path;
use std::sync::{Arc, OnceLock, RwLock};
use std::sync::{Arc, OnceLock, PoisonError, RwLock};
use titan::{CsvError, CsvReader, GlobalId};
use crate::data::logic_data::LogicData;
use crate::data::logic_data_table::LogicDataTable;
@ -110,11 +110,15 @@ impl LogicDataTables {
Self::default()
}
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()
}
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),
None => Arc::clone(EMPTY.get_or_init(|| Arc::new(LogicDataTables::empty()))),
}
@ -122,7 +126,7 @@ impl LogicDataTables {
pub fn is_installed() -> bool {
INSTANCE
.read()
.expect("data table lock poisoned")
.unwrap_or_else(PoisonError::into_inner)
.as_ref()
.map(|tables| tables.is_loaded())
.unwrap_or(false)