mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-11-19 06:58:24 +01:00
fix(models): return a database error instead of panicking when the pool is exhausted
Two users on 2026.7.x reported the app going half-dead: local editing kept
working, but Send did nothing and every encrypted secret rendered blank until
they restarted. The webview console carried a Rust task panic —
Delete task failed: task 1314 panicked with message
"Failed to get new DB connection from the pool: Error(None)"
`Error(None)` is r2d2's acquire timeout. `QueryManager::connect` and `with_tx`
turned that timeout into `expect`, so a pool that was momentarily full took down
whatever task asked for a connection instead of reporting a failure the caller
could show, retry, or ignore. Every DB-backed path shares those two functions,
which is why one stalled pool reads as "Send is dead and the secrets are gone".
Acquisition is now fallible end to end: `connect()` and `BlobManager::connect()`
return `Result`, and so do the `db()`/`blobs()` accessors on every host. Call
sites propagate with `?` where they already returned a result; the fire-and-forget
writers (streaming events, the model-change poller) log and carry on. `with_conn`
had no callers and only added a third panic, so it is gone.
Two places held a pooled connection across work that has nothing to do with the
database and can block for a long time — the OS keyring in
`EncryptionManager::get_workspace_key`, and the sync directory walk in
`cmd_sync_calculate`. Both now hand the connection back first. Those are the
paths behind the two visible symptoms.
Not fixed here: the gRPC streaming block in yaak-app-client still `.unwrap()`s
its database writes, as it did before, so acquisition failures panic there too.
`ProxyQueryManager` in the separate proxy app keeps its own `expect`.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7f8b7bf567
commit
c9e884d4fe
57 files changed
+899
-627
No files matched your search
@@ -13,7 +13,6 @@ use tokio::task::JoinHandle;
|
||||
use yaak::plugin_events::{
|
||||
GroupedPluginEvent, HostRequest, SharedPluginEventContext, handle_shared_plugin_event,
|
||||
};
|
||||
use yaak_models::render::{render_grpc_request, render_http_request};
|
||||
use yaak::response_body::FileResponseBodyStore;
|
||||
use yaak::send::{SendHttpRequestWithPluginsParams, send_http_request_with_plugins};
|
||||
use yaak_crypto::manager::EncryptionManager;
|
||||
@@ -24,6 +23,7 @@ use yaak_models::models::Environment;
|
||||
use yaak_models::queries::any_request::AnyRequest;
|
||||
use yaak_models::query_manager::QueryManager;
|
||||
use yaak_models::render::make_vars_hashmap;
|
||||
use yaak_models::render::{render_grpc_request, render_http_request};
|
||||
use yaak_models::util::UpdateSource;
|
||||
use yaak_plugins::events::{
|
||||
EmptyPayload, ErrorResponse, FormInput, GetCookieValueResponse, InternalEvent,
|
||||
@@ -150,7 +150,11 @@ async fn build_plugin_reply(
|
||||
Some(InternalEventPayload::ShowToastResponse(EmptyPayload {}))
|
||||
}
|
||||
HostRequest::ListOpenWorkspaces(_) => {
|
||||
let workspaces = match host_context.query_manager.connect().list_workspaces() {
|
||||
let workspaces = match host_context
|
||||
.query_manager
|
||||
.connect()
|
||||
.and_then(|db| db.list_workspaces())
|
||||
{
|
||||
Ok(workspaces) => workspaces
|
||||
.into_iter()
|
||||
.map(|w| WorkspaceInfo { id: w.id.clone(), name: w.name, label: w.id })
|
||||
@@ -189,7 +193,7 @@ async fn build_plugin_reply(
|
||||
match host_context
|
||||
.query_manager
|
||||
.connect()
|
||||
.list_cookie_jars(http_request.workspace_id.as_str())
|
||||
.and_then(|db| db.list_cookie_jars(http_request.workspace_id.as_str()))
|
||||
{
|
||||
Ok(cookie_jars) => cookie_jars
|
||||
.into_iter()
|
||||
@@ -264,19 +268,20 @@ async fn build_plugin_reply(
|
||||
..event.context.clone()
|
||||
};
|
||||
|
||||
let environment_chain =
|
||||
match host_context.query_manager.connect().resolve_environments(
|
||||
let environment_chain = match host_context.query_manager.connect().and_then(|db| {
|
||||
db.resolve_environments(
|
||||
&grpc_request.workspace_id,
|
||||
grpc_request.folder_id.as_deref(),
|
||||
execution_context.environment_id.as_deref(),
|
||||
) {
|
||||
Ok(chain) => chain,
|
||||
Err(err) => {
|
||||
return Some(InternalEventPayload::ErrorResponse(ErrorResponse {
|
||||
error: format!("Failed to resolve environments in CLI: {err}"),
|
||||
}));
|
||||
}
|
||||
};
|
||||
)
|
||||
}) {
|
||||
Ok(chain) => chain,
|
||||
Err(err) => {
|
||||
return Some(InternalEventPayload::ErrorResponse(ErrorResponse {
|
||||
error: format!("Failed to resolve environments in CLI: {err}"),
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
let template_callback = PluginTemplateCallback::new(
|
||||
host_context.plugin_manager.clone(),
|
||||
@@ -324,19 +329,20 @@ async fn build_plugin_reply(
|
||||
..event.context.clone()
|
||||
};
|
||||
|
||||
let environment_chain =
|
||||
match host_context.query_manager.connect().resolve_environments(
|
||||
let environment_chain = match host_context.query_manager.connect().and_then(|db| {
|
||||
db.resolve_environments(
|
||||
&http_request.workspace_id,
|
||||
http_request.folder_id.as_deref(),
|
||||
execution_context.environment_id.as_deref(),
|
||||
) {
|
||||
Ok(chain) => chain,
|
||||
Err(err) => {
|
||||
return Some(InternalEventPayload::ErrorResponse(ErrorResponse {
|
||||
error: format!("Failed to resolve environments in CLI: {err}"),
|
||||
}));
|
||||
}
|
||||
};
|
||||
)
|
||||
}) {
|
||||
Ok(chain) => chain,
|
||||
Err(err) => {
|
||||
return Some(InternalEventPayload::ErrorResponse(ErrorResponse {
|
||||
error: format!("Failed to resolve environments in CLI: {err}"),
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
let template_callback = PluginTemplateCallback::new(
|
||||
host_context.plugin_manager.clone(),
|
||||
@@ -380,7 +386,11 @@ async fn build_plugin_reply(
|
||||
};
|
||||
|
||||
let folder_id = execution_context.request_id.as_ref().and_then(|rid| {
|
||||
match host_context.query_manager.connect().get_any_request(rid) {
|
||||
match host_context
|
||||
.query_manager
|
||||
.connect()
|
||||
.and_then(|db| db.get_any_request(rid))
|
||||
{
|
||||
Ok(AnyRequest::HttpRequest(r)) => r.folder_id,
|
||||
Ok(AnyRequest::GrpcRequest(r)) => r.folder_id,
|
||||
Ok(AnyRequest::WebsocketRequest(r)) => r.folder_id,
|
||||
@@ -388,19 +398,20 @@ async fn build_plugin_reply(
|
||||
}
|
||||
});
|
||||
|
||||
let environment_chain =
|
||||
match host_context.query_manager.connect().resolve_environments(
|
||||
let environment_chain = match host_context.query_manager.connect().and_then(|db| {
|
||||
db.resolve_environments(
|
||||
&workspace_id,
|
||||
folder_id.as_deref(),
|
||||
execution_context.environment_id.as_deref(),
|
||||
) {
|
||||
Ok(chain) => chain,
|
||||
Err(err) => {
|
||||
return Some(InternalEventPayload::ErrorResponse(ErrorResponse {
|
||||
error: format!("Failed to resolve environments in CLI: {err}"),
|
||||
}));
|
||||
}
|
||||
};
|
||||
)
|
||||
}) {
|
||||
Ok(chain) => chain,
|
||||
Err(err) => {
|
||||
return Some(InternalEventPayload::ErrorResponse(ErrorResponse {
|
||||
error: format!("Failed to resolve environments in CLI: {err}"),
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
let template_callback = PluginTemplateCallback::new(
|
||||
host_context.plugin_manager.clone(),
|
||||
@@ -476,15 +487,18 @@ async fn build_plugin_reply(
|
||||
));
|
||||
};
|
||||
|
||||
let cookie_jar =
|
||||
match host_context.query_manager.connect().get_cookie_jar(cookie_jar_id) {
|
||||
Ok(cookie_jar) => cookie_jar,
|
||||
Err(err) => {
|
||||
return Some(InternalEventPayload::ErrorResponse(ErrorResponse {
|
||||
error: format!("Failed to load cookie jar in CLI: {err}"),
|
||||
}));
|
||||
}
|
||||
};
|
||||
let cookie_jar = match host_context
|
||||
.query_manager
|
||||
.connect()
|
||||
.and_then(|db| db.get_cookie_jar(cookie_jar_id))
|
||||
{
|
||||
Ok(cookie_jar) => cookie_jar,
|
||||
Err(err) => {
|
||||
return Some(InternalEventPayload::ErrorResponse(ErrorResponse {
|
||||
error: format!("Failed to load cookie jar in CLI: {err}"),
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
let names = cookie_jar.cookies.into_iter().map(|c| c.name).collect();
|
||||
|
||||
@@ -499,15 +513,18 @@ async fn build_plugin_reply(
|
||||
));
|
||||
};
|
||||
|
||||
let cookie_jar =
|
||||
match host_context.query_manager.connect().get_cookie_jar(cookie_jar_id) {
|
||||
Ok(cookie_jar) => cookie_jar,
|
||||
Err(err) => {
|
||||
return Some(InternalEventPayload::ErrorResponse(ErrorResponse {
|
||||
error: format!("Failed to load cookie jar in CLI: {err}"),
|
||||
}));
|
||||
}
|
||||
};
|
||||
let cookie_jar = match host_context
|
||||
.query_manager
|
||||
.connect()
|
||||
.and_then(|db| db.get_cookie_jar(cookie_jar_id))
|
||||
{
|
||||
Ok(cookie_jar) => cookie_jar,
|
||||
Err(err) => {
|
||||
return Some(InternalEventPayload::ErrorResponse(ErrorResponse {
|
||||
error: format!("Failed to load cookie jar in CLI: {err}"),
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
let value =
|
||||
get_cookie_value_from_jar(cookie_jar.cookies, &req.name, req.domain.as_deref());
|
||||
|
||||
Reference in new issue
Block a user