From eb2cc58dcab66bb35bca3b58feaa762332a4d3ce Mon Sep 17 00:00:00 2001 From: Shreyas Date: Fri, 8 Aug 2025 13:40:02 +0530 Subject: [PATCH] feat(desktop): explore random port for IPv6 compat (#5311) This attempts to resolve app startup failures on Linux systems where IPv6 is disabled at the kernel level by replacing the dual-stack port selection logic with network interface discovery. Closes FE-912 Closes #4962 --- .../hoppscotch-common/src/components.d.ts | 3 +- .../hoppscotch-desktop/src-tauri/Cargo.lock | 36 +++++++++++++------ .../hoppscotch-desktop/src-tauri/Cargo.toml | 2 +- .../hoppscotch-desktop/src-tauri/src/lib.rs | 8 ++++- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/packages/hoppscotch-common/src/components.d.ts b/packages/hoppscotch-common/src/components.d.ts index 3392c2b4..a34181a0 100644 --- a/packages/hoppscotch-common/src/components.d.ts +++ b/packages/hoppscotch-common/src/components.d.ts @@ -211,9 +211,7 @@ declare module 'vue' { IconLucideArrowUpRight: typeof import('~icons/lucide/arrow-up-right')['default'] IconLucideBrush: typeof import('~icons/lucide/brush')['default'] IconLucideCheckCircle: typeof import('~icons/lucide/check-circle')['default'] - IconLucideChevronDown: typeof import('~icons/lucide/chevron-down')['default'] IconLucideChevronRight: typeof import('~icons/lucide/chevron-right')['default'] - IconLucideChevronUp: typeof import('~icons/lucide/chevron-up')['default'] IconLucideCircleCheck: typeof import('~icons/lucide/circle-check')['default'] IconLucideGlobe: typeof import('~icons/lucide/globe')['default'] IconLucideHelpCircle: typeof import('~icons/lucide/help-circle')['default'] @@ -223,6 +221,7 @@ declare module 'vue' { IconLucideListEnd: typeof import('~icons/lucide/list-end')['default'] IconLucideMinus: typeof import('~icons/lucide/minus')['default'] IconLucidePlusCircle: typeof import('~icons/lucide/plus-circle')['default'] + IconLucideRss: typeof import('~icons/lucide/rss')['default'] IconLucideSearch: typeof import('~icons/lucide/search')['default'] IconLucideTriangleAlert: typeof import('~icons/lucide/triangle-alert')['default'] IconLucideUsers: typeof import('~icons/lucide/users')['default'] diff --git a/packages/hoppscotch-desktop/src-tauri/Cargo.lock b/packages/hoppscotch-desktop/src-tauri/Cargo.lock index 3289e06b..6c06a5ab 100644 --- a/packages/hoppscotch-desktop/src-tauri/Cargo.lock +++ b/packages/hoppscotch-desktop/src-tauri/Cargo.lock @@ -2222,7 +2222,7 @@ dependencies = [ "dirs 6.0.0", "file-rotate", "native-dialog", - "portpicker", + "random-port", "semver", "serde", "serde_json", @@ -3151,6 +3151,18 @@ dependencies = [ "jni-sys", ] +[[package]] +name = "network-interface" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a43439bf756eed340bdf8feba761e2d50c7d47175d87545cd5cbe4a137c4d1" +dependencies = [ + "cc", + "libc", + "thiserror 1.0.69", + "winapi", +] + [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -3247,7 +3259,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" dependencies = [ - "proc-macro-crate 1.3.1", + "proc-macro-crate 3.3.0", "proc-macro2", "quote", "syn 2.0.90", @@ -3922,15 +3934,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "portpicker" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be97d76faf1bfab666e1375477b23fde79eccf0276e9b63b92a39d676a889ba9" -dependencies = [ - "rand 0.8.5", -] - [[package]] name = "powerfmt" version = "0.2.0" @@ -4195,6 +4198,17 @@ dependencies = [ "rand_core 0.5.1", ] +[[package]] +name = "random-port" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52b7d0e298a1b2f2f46c8d5da944c80ed1e5e6b032521cc44ee2b1dcbe2b94a" +dependencies = [ + "network-interface", + "rand 0.8.5", + "thiserror 1.0.69", +] + [[package]] name = "raw-window-handle" version = "0.5.2" diff --git a/packages/hoppscotch-desktop/src-tauri/Cargo.toml b/packages/hoppscotch-desktop/src-tauri/Cargo.toml index d3dd515d..2e504003 100644 --- a/packages/hoppscotch-desktop/src-tauri/Cargo.toml +++ b/packages/hoppscotch-desktop/src-tauri/Cargo.toml @@ -33,7 +33,7 @@ tauri-plugin-appload = { git = "https://github.com/CuriousCorrelation/tauri-plug tauri-plugin-relay = { git = "https://github.com/CuriousCorrelation/tauri-plugin-relay", rev = "0147ac1bb29d3b88d6652432a482bd86f0174506" } axum = "0.8.1" tower-http = { version = "0.6.2", features = ["cors"] } -portpicker = "0.1.1" +random-port = "0.1.1" tokio = "1.43.0" tauri-plugin-process = "2.2.0" file-rotate = "0.8.0" diff --git a/packages/hoppscotch-desktop/src-tauri/src/lib.rs b/packages/hoppscotch-desktop/src-tauri/src/lib.rs index 00f9f18e..572da8c2 100644 --- a/packages/hoppscotch-desktop/src-tauri/src/lib.rs +++ b/packages/hoppscotch-desktop/src-tauri/src/lib.rs @@ -9,6 +9,8 @@ use tauri_plugin_appload::VendorConfigBuilder; use tauri_plugin_deep_link::DeepLinkExt; use tauri_plugin_window_state::StateFlags; +use random_port::{PortPicker, Protocol}; + pub const HOPPSCOTCH_DESKTOP_IDENTIFIER: &'static str = "io.hoppscotch.desktop"; static SERVER_PORT: OnceLock = OnceLock::new(); @@ -40,7 +42,11 @@ fn quit_app(app: tauri::AppHandle) -> Result<(), String> { pub fn run() { tauri::Builder::default() .setup(|app| { - let server_port = portpicker::pick_unused_port().expect("Cannot find unused port"); + let server_port: u16 = PortPicker::new() + .protocol(Protocol::Tcp) + .port_range(15000..=25000) + .pick() + .expect("Cannot find unused port"); tracing::info!("Selected server port: {}", server_port); SERVER_PORT .set(server_port)