fix: Replace futures::executor::block_on with thread::spawn in SET USER
All checks were successful
BotServer CI/CD / build (push) Successful in 4m25s
All checks were successful
BotServer CI/CD / build (push) Successful in 4m25s
- Fixes panic: Cannot start a runtime from within a runtime
- set_user.rs was using futures::executor::block_on directly in Rhai callback
- Now uses std:🧵:spawn + new_current_thread().block_on() pattern
- This is called during bootstrap and was causing startup crash
This commit is contained in:
parent
7cd759f810
commit
6ec82c27a6
1 changed files with 18 additions and 6 deletions
|
|
@ -17,16 +17,28 @@ pub fn set_user_keyword(state: Arc<AppState>, user: UserSession, engine: &mut En
|
||||||
Ok(user_id) => {
|
Ok(user_id) => {
|
||||||
let state_for_spawn = Arc::clone(&state_clone);
|
let state_for_spawn = Arc::clone(&state_clone);
|
||||||
let user_clone_spawn = user_clone.clone();
|
let user_clone_spawn = user_clone.clone();
|
||||||
let mut session_manager =
|
let (tx, rx) = std::sync::mpsc::channel();
|
||||||
futures::executor::block_on(state_for_spawn.session_manager.lock());
|
std::thread::spawn(move || {
|
||||||
|
let rt = tokio::runtime::Builder::new_current_thread()
|
||||||
if let Err(e) = session_manager.update_user_id(user_clone_spawn.id, user_id) {
|
.enable_all()
|
||||||
error!("Failed to update user ID in session: {e}");
|
.build();
|
||||||
} else {
|
let result = if let Ok(rt) = rt {
|
||||||
|
rt.block_on(async {
|
||||||
|
let mut session_manager = state_for_spawn.session_manager.lock().await;
|
||||||
|
session_manager.update_user_id(user_clone_spawn.id, user_id)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Err("Failed to create runtime".into())
|
||||||
|
};
|
||||||
|
let _ = tx.send(result);
|
||||||
|
});
|
||||||
|
if let Ok(Ok(())) = rx.recv() {
|
||||||
trace!(
|
trace!(
|
||||||
"Updated session {} to user ID: {user_id}",
|
"Updated session {} to user ID: {user_id}",
|
||||||
user_clone_spawn.id
|
user_clone_spawn.id
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
error!("Failed to update user ID in session");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue