[PR #5311] [MERGED] feat(desktop): explore random port for IPv6 compat #5153

Closed
opened 2026-03-17 02:37:40 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/5311
Author: @CuriousCorrelation
Created: 8/6/2025
Status: Merged
Merged: 8/8/2025
Merged by: @jamesgeorge007

Base: patchHead: desktop-feat-explore-stable-port-selection


📝 Commits (1)

  • fbaa3cf feat(desktop): explore random port for IPv6 compat

📊 Changes

4 files changed (+34 additions, -15 deletions)

View changed files

📝 packages/hoppscotch-common/src/components.d.ts (+1 -2)
📝 packages/hoppscotch-desktop/src-tauri/Cargo.lock (+25 -11)
📝 packages/hoppscotch-desktop/src-tauri/Cargo.toml (+1 -1)
📝 packages/hoppscotch-desktop/src-tauri/src/lib.rs (+7 -1)

📄 Description

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

The current portpicker-rs library uses AND logic requiring both IPv4
and IPv6 socket binding to succeed, causing "Cannot find unused port"
errors when IPv6 is disabled via ipv6.disable=1 even though IPv4
ports are available and the application only needs IPv4 connectivity
for the local HTTP server.

This affects users who disable IPv6 for VPN compatibility (Outline VPN)
or enterprise security policies where re-enabling IPv6 is not viable.

What's changed

Replaced portpicker dependency with random-port library that uses
actual network interface discovery instead of assuming dual-stack
availability. The new implementation discovers available network
interfaces using the network-interface crate, tests only protocols
available on the system, and provides fallback behavior when IPv6
is disabled.

From this:

let server_port = portpicker::pick_unused_port()
    .expect("Cannot find unused port");

To this:

let server_port: u16 = PortPicker::new()
    .protocol(Protocol::Tcp)
    .port_range(15000..=25000)
    .pick()
    .expect("Cannot find unused port");

Implementation

Updated Cargo.toml to replace portpicker = "0.1.1" with
random-port = "0.1.1" and modified port selection logic in
setup_server function in src/lib.rs. The new implementation
maintains the same port range (15000-25000) and TCP protocol
requirements.

Backwards Compat

The change preserves all existing functionality including server
initialization, port availability checking, and HTTP server binding
with no changes to external API or user experience.

Testing

Testing should verify port selection works on dual-stack systems with
IPv6 enabled, IPv6-disabled systems with ipv6.disable=1 kernel
parameter. The implementation should also maintain existing port
conflict detection, and should resolve IPv6 compat issues.

NOTE: The best way to test this works is by simply trying the login flow,
since login server uses random port to fetch the auth tokens.

Notes to reviewers

This is an exploratory fix based on user reports from GitHub issue
#4962. random-port library uses a different approach to port selection
that handles diverse network configs better.

NOTE: Due to the verity of environments, this will be an exploratory PR
rather than a confirmed fix at the moment.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/5311 **Author:** [@CuriousCorrelation](https://github.com/CuriousCorrelation) **Created:** 8/6/2025 **Status:** ✅ Merged **Merged:** 8/8/2025 **Merged by:** [@jamesgeorge007](https://github.com/jamesgeorge007) **Base:** `patch` ← **Head:** `desktop-feat-explore-stable-port-selection` --- ### 📝 Commits (1) - [`fbaa3cf`](https://github.com/hoppscotch/hoppscotch/commit/fbaa3cf9259a964f406087ab5089c0b06df38db1) feat(desktop): explore random port for IPv6 compat ### 📊 Changes **4 files changed** (+34 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-common/src/components.d.ts` (+1 -2) 📝 `packages/hoppscotch-desktop/src-tauri/Cargo.lock` (+25 -11) 📝 `packages/hoppscotch-desktop/src-tauri/Cargo.toml` (+1 -1) 📝 `packages/hoppscotch-desktop/src-tauri/src/lib.rs` (+7 -1) </details> ### 📄 Description 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 The current `portpicker-rs` library uses AND logic requiring both IPv4 and IPv6 socket binding to succeed, causing "Cannot find unused port" errors when IPv6 is disabled via `ipv6.disable=1` even though IPv4 ports are available and the application only needs IPv4 connectivity for the local HTTP server. This affects users who disable IPv6 for VPN compatibility (Outline VPN) or enterprise security policies where re-enabling IPv6 is not viable. ### What's changed Replaced `portpicker` dependency with `random-port` library that uses actual network interface discovery instead of assuming dual-stack availability. The new implementation discovers available network interfaces using the `network-interface` crate, tests only protocols available on the system, and provides fallback behavior when IPv6 is disabled. From this: ```rust let server_port = portpicker::pick_unused_port() .expect("Cannot find unused port"); ```` To this: ```rust let server_port: u16 = PortPicker::new() .protocol(Protocol::Tcp) .port_range(15000..=25000) .pick() .expect("Cannot find unused port"); ```` ### Implementation Updated `Cargo.toml` to replace `portpicker = "0.1.1"` with `random-port = "0.1.1"` and modified port selection logic in `setup_server` function in `src/lib.rs`. The new implementation maintains the same port range (15000-25000) and TCP protocol requirements. ### Backwards Compat The change preserves all existing functionality including server initialization, port availability checking, and HTTP server binding with no changes to external API or user experience. ### Testing Testing should verify port selection works on dual-stack systems with IPv6 enabled, IPv6-disabled systems with `ipv6.disable=1` kernel parameter. The implementation should also maintain existing port conflict detection, and should resolve IPv6 compat issues. **NOTE**: The best way to test this works is by simply trying the login flow, since login server uses random port to fetch the auth tokens. ### Notes to reviewers This is an exploratory fix based on user reports from GitHub issue #4962. random-port library uses a different approach to port selection that handles diverse network configs better. **NOTE**: Due to the verity of environments, this will be an exploratory PR rather than a confirmed fix at the moment. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-17 02:37:40 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#5153
No description provided.