Have cancellation work before the request is sent

This commit is contained in:
Gregory Schier
2026-02-02 07:09:48 -08:00
parent c4ce458f79
commit eff4519d91

View File

@@ -182,7 +182,14 @@ async fn send_http_request_inner<R: Runtime>(
); );
let env_chain = let env_chain =
window.db().resolve_environments(&workspace.id, folder_id, environment_id.as_deref())?; window.db().resolve_environments(&workspace.id, folder_id, environment_id.as_deref())?;
let request = render_http_request(&resolved, env_chain, &cb, &RenderOptions::throw()).await?; let mut cancel_rx = cancelled_rx.clone();
let render_options = RenderOptions::throw();
let request = tokio::select! {
result = render_http_request(&resolved, env_chain, &cb, &render_options) => result?,
_ = cancel_rx.changed() => {
return Err(GenericError("Request canceled".to_string()));
}
};
// Build the sendable request using the new SendableHttpRequest type // Build the sendable request using the new SendableHttpRequest type
let options = SendableHttpRequestOptions { let options = SendableHttpRequestOptions {
@@ -244,16 +251,22 @@ async fn send_http_request_inner<R: Runtime>(
}) })
.await?; .await?;
// Apply authentication to the request // Apply authentication to the request, racing against cancellation since
apply_authentication( // auth plugins (e.g. OAuth2) can block indefinitely waiting for user action.
&window, let mut cancel_rx = cancelled_rx.clone();
&mut sendable_request, tokio::select! {
&request, result = apply_authentication(
auth_context_id, &window,
&plugin_manager, &mut sendable_request,
plugin_context, &request,
) auth_context_id,
.await?; &plugin_manager,
plugin_context,
) => result?,
_ = cancel_rx.changed() => {
return Err(GenericError("Request canceled".to_string()));
}
};
let cookie_store = maybe_cookie_store.as_ref().map(|(cs, _)| cs.clone()); let cookie_store = maybe_cookie_store.as_ref().map(|(cs, _)| cs.clone());
let result = execute_transaction( let result = execute_transaction(