fix: remove block_in_place wrappers that panic inside spawn_blocking
Some checks are pending
BotServer CI/CD / build (push) Waiting to run
Some checks are pending
BotServer CI/CD / build (push) Waiting to run
Root cause: block_in_place + new_current_thread().block_on() panics when called from within tokio::task::spawn_blocking because block_in_place is designed for async worker threads, not blocking threads. Fix: Remove all block_in_place wrappers and use new_current_thread().build().block_on() directly. This works from both async contexts and spawn_blocking contexts. Affected: utils.rs (get_database_url_sync, get_work_path)
This commit is contained in:
parent
c2982f2a33
commit
21170faea9
1 changed files with 14 additions and 18 deletions
|
|
@ -54,13 +54,11 @@ pub fn get_database_url_sync() -> Result<String> {
|
||||||
let guard = SECRETS_MANAGER.read().map_err(|e| anyhow::anyhow!("Lock poisoned: {}", e))?;
|
let guard = SECRETS_MANAGER.read().map_err(|e| anyhow::anyhow!("Lock poisoned: {}", e))?;
|
||||||
if let Some(ref manager) = *guard {
|
if let Some(ref manager) = *guard {
|
||||||
if tokio::runtime::Handle::try_current().is_ok() {
|
if tokio::runtime::Handle::try_current().is_ok() {
|
||||||
return tokio::task::block_in_place(|| {
|
let rt = tokio::runtime::Builder::new_current_thread()
|
||||||
let rt = tokio::runtime::Builder::new_current_thread()
|
.enable_all()
|
||||||
.enable_all()
|
.build()
|
||||||
.build()
|
.map_err(|e| anyhow::anyhow!("Failed to create runtime: {}", e))?;
|
||||||
.map_err(|e| anyhow::anyhow!("Failed to create runtime: {}", e))?;
|
return rt.block_on(manager.get_database_url());
|
||||||
rt.block_on(manager.get_database_url())
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
let rt = tokio::runtime::Runtime::new()
|
let rt = tokio::runtime::Runtime::new()
|
||||||
.map_err(|e| anyhow::anyhow!("Failed to create runtime: {}", e))?;
|
.map_err(|e| anyhow::anyhow!("Failed to create runtime: {}", e))?;
|
||||||
|
|
@ -86,17 +84,15 @@ pub fn get_secrets_manager_sync() -> Option<SecretsManager> {
|
||||||
pub fn get_work_path() -> String {
|
pub fn get_work_path() -> String {
|
||||||
let sm = get_secrets_manager_sync();
|
let sm = get_secrets_manager_sync();
|
||||||
if let Some(sm) = sm {
|
if let Some(sm) = sm {
|
||||||
tokio::task::block_in_place(|| {
|
let rt = tokio::runtime::Builder::new_current_thread()
|
||||||
let rt = tokio::runtime::Builder::new_current_thread()
|
.enable_all()
|
||||||
.enable_all()
|
.build()
|
||||||
.build()
|
.ok();
|
||||||
.ok();
|
match rt {
|
||||||
match rt {
|
Some(rt) => rt.block_on(sm.get_value("gbo/app", "work_path"))
|
||||||
Some(rt) => rt.block_on(sm.get_value("gbo/app", "work_path"))
|
.unwrap_or_else(|_| "./work".to_string()),
|
||||||
.unwrap_or_else(|_| "./work".to_string()),
|
None => "./work".to_string(),
|
||||||
None => "./work".to_string(),
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
"./work".to_string()
|
"./work".to_string()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue