From b71bc2cc9233b75949bd9bc327189abd77a0bb1f Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Sat, 2 Aug 2025 09:37:28 -0700 Subject: [PATCH] Fix gRPC/WS hang because of ALPN https://feedback.yaak.app/p/grpc-stalls-at-inspecting-schema-no-timeout-no-manual-proto --- src-tauri/src/http_request.rs | 2 +- src-tauri/yaak-grpc/src/transport.rs | 5 ++++- src-tauri/yaak-http/src/tls.rs | 9 ++++++--- src-tauri/yaak-ws/src/connect.rs | 9 ++++++--- src-web/components/GrpcProtoSelectionDialog.tsx | 6 ++---- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src-tauri/src/http_request.rs b/src-tauri/src/http_request.rs index 98550f5f..1c792f39 100644 --- a/src-tauri/src/http_request.rs +++ b/src-tauri/src/http_request.rs @@ -111,7 +111,7 @@ pub async fn send_http_request( .referer(false) .tls_info(true); - let tls_config = yaak_http::tls::get_config(workspace.setting_validate_certificates); + let tls_config = yaak_http::tls::get_config(workspace.setting_validate_certificates, true); client_builder = client_builder.use_preconfigured_tls(tls_config); match settings.proxy { diff --git a/src-tauri/yaak-grpc/src/transport.rs b/src-tauri/yaak-grpc/src/transport.rs index 2541003b..242d8195 100644 --- a/src-tauri/yaak-grpc/src/transport.rs +++ b/src-tauri/yaak-grpc/src/transport.rs @@ -4,8 +4,11 @@ use hyper_util::client::legacy::Client; use hyper_util::rt::TokioExecutor; use tonic::body::BoxBody; +// I think ALPN breaks this because we're specifying http2_only +const WITH_ALPN: bool = false; + pub(crate) fn get_transport(validate_certificates: bool) -> Client, BoxBody> { - let tls_config = yaak_http::tls::get_config(validate_certificates); + let tls_config = yaak_http::tls::get_config(validate_certificates, WITH_ALPN); let mut http = HttpConnector::new(); http.enforce_http(false); diff --git a/src-tauri/yaak-http/src/tls.rs b/src-tauri/yaak-http/src/tls.rs index 25cf80c2..054f96cf 100644 --- a/src-tauri/yaak-http/src/tls.rs +++ b/src-tauri/yaak-http/src/tls.rs @@ -5,7 +5,7 @@ use rustls::{ClientConfig, DigitallySignedStruct, SignatureScheme}; use rustls_platform_verifier::BuilderVerifierExt; use std::sync::Arc; -pub fn get_config(validate_certificates: bool) -> ClientConfig { +pub fn get_config(validate_certificates: bool, with_alpn: bool) -> ClientConfig { let arc_crypto_provider = Arc::new(ring::default_provider()); let config_builder = ClientConfig::builder_with_provider(arc_crypto_provider) .with_safe_default_protocol_versions() @@ -19,8 +19,11 @@ pub fn get_config(validate_certificates: bool) -> ClientConfig { .with_custom_certificate_verifier(Arc::new(NoVerifier)) .with_no_client_auth() }; - // Required for http/2 support - client.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()]; + + if with_alpn { + client.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()]; + } + client } diff --git a/src-tauri/yaak-ws/src/connect.rs b/src-tauri/yaak-ws/src/connect.rs index 2aa281c1..aa8725be 100644 --- a/src-tauri/yaak-ws/src/connect.rs +++ b/src-tauri/yaak-ws/src/connect.rs @@ -7,16 +7,19 @@ use tokio_tungstenite::tungstenite::handshake::client::Response; use tokio_tungstenite::tungstenite::http::HeaderValue; use tokio_tungstenite::tungstenite::protocol::WebSocketConfig; use tokio_tungstenite::{ - connect_async_tls_with_config, Connector, MaybeTlsStream, WebSocketStream, + Connector, MaybeTlsStream, WebSocketStream, connect_async_tls_with_config, }; +// Enabling ALPN breaks websocket requests +const WITH_ALPN: bool = false; + pub(crate) async fn ws_connect( url: &str, headers: HeaderMap, validate_certificates: bool, ) -> crate::error::Result<(WebSocketStream>, Response)> { info!("Connecting to WS {url}"); - let tls_config = yaak_http::tls::get_config(validate_certificates); + let tls_config = yaak_http::tls::get_config(validate_certificates, WITH_ALPN); let mut req = url.into_client_request()?; let req_headers = req.headers_mut(); @@ -34,4 +37,4 @@ pub(crate) async fn ws_connect( ) .await?; Ok((stream, response)) -} \ No newline at end of file +} diff --git a/src-web/components/GrpcProtoSelectionDialog.tsx b/src-web/components/GrpcProtoSelectionDialog.tsx index bd144df1..31d945de 100644 --- a/src-web/components/GrpcProtoSelectionDialog.tsx +++ b/src-web/components/GrpcProtoSelectionDialog.tsx @@ -43,7 +43,7 @@ function GrpcProtoSelectionDialogWithRequest({ request }: Props & { request: Grp return ( {/* Buttons on top so they get focus first */} - +