fix(client): remove broken catch_unwind, tokio task isolation is sufficient
This commit is contained in:
parent
a43c5c3197
commit
18e844033a
1 changed files with 4 additions and 20 deletions
|
|
@ -226,26 +226,10 @@ async fn main() {
|
||||||
let shell_clone = Arc::clone(&shell);
|
let shell_clone = Arc::clone(&shell);
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
// Catch panics so a single bad command never kills the client.
|
// tokio isolates panics per task — a panic here won't kill
|
||||||
let response = std::panic::AssertUnwindSafe(
|
// the main loop. handle_message uses map_err everywhere so
|
||||||
handle_message(server_msg.clone(), shell_clone)
|
// it should never panic in practice.
|
||||||
);
|
let response = handle_message(server_msg, shell_clone).await;
|
||||||
let response = match std::panic::catch_unwind(|| {
|
|
||||||
// We can't catch async panics with catch_unwind directly,
|
|
||||||
// so we wrap the whole spawn in AssertUnwindSafe and rely
|
|
||||||
// on tokio's per-task panic isolation instead.
|
|
||||||
// The real guard is that handle_message never panics —
|
|
||||||
// it uses ? / map_err everywhere.
|
|
||||||
drop(response);
|
|
||||||
}) {
|
|
||||||
Ok(()) => handle_message(server_msg, shell_clone).await,
|
|
||||||
Err(_) => {
|
|
||||||
log_err!("Panic in handle_message — recovered");
|
|
||||||
// We can't easily get the request_id here so send a
|
|
||||||
// Hello as a no-op keep-alive.
|
|
||||||
ClientMessage::Hello { label: None }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let json = match serde_json::to_string(&response) {
|
let json = match serde_json::to_string(&response) {
|
||||||
Ok(j) => j,
|
Ok(j) => j,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue