Skip to content

Commit cc5f939

Browse files
committed
v0.8.0: dynamic IP discovery (from PR #9), OpenWRT fd fix (#8), Windows UI diagnostics (#7)
Three user-reported fixes / features in one release. === PR #9 — dynamic Google IP discovery (@v4g4b0nd-0x76) === Already merged in the previous commit. Opt-in via 'fetch_ips_from_api' in config. Pulls goog.json from www.gstatic.com, maps it against resolved IPs of well-known Google domains, samples from matching CIDRs, and validates each candidate with gws / x-google / alt-svc response-header checks. Graceful fallback to the static list if the fetch fails or nothing passes validation. Default is off so existing users are unaffected. Closes #10. === Issue #8 — OpenWRT: 'accept: No file descriptors available' === OpenWRT routers ship a very low RLIMIT_NOFILE (often 1024, sometimes 256 on constrained devices). A browser's burst of ~30 parallel sub- resource requests can fill the limit within seconds, after which accept(2) returns EMFILE and the proxy is effectively dead. Two-fold fix: 1. New assets/openwrt/mhrv-rs.init now sets procd limits nofile= "16384 16384" on the service. procd raises the per-process fd limit before the binary even starts. 2. New src/rlimit.rs best-effort-raises RLIMIT_NOFILE in the binary itself (Unix only, no new runtime deps — libc is already transitively present via tokio). Targets 16384 soft, capped to whatever hard limit the kernel already allows the user (so it doesn't need root). Both layers mean the fix applies whether the user runs via /etc/init.d/mhrv-rs start (procd limits kick in) or ./mhrv-rs --config ... (in-binary bump kicks in) or any other invocation path. Closes #8. === Issue #7 — Windows UI crashes silently === User report: on Win 11, run.bat prints 'Starting mhrv-rs UI...' and exits clean, but no UI window ever appears. Root cause: the old run.bat used 'start "" "mhrv-rs-ui.exe"' which returns immediately — if the UI binary dies at launch time (missing GPU driver, RDP without GL accel, AV blocking, …), the crash is invisible because start already disowned the child. Fix: run the UI in-place (not via 'start'), so its stderr and exit code land in the run.bat cmd window. On non-zero exit print a helpful checklist of common Windows launch failures and pause so the user can screenshot the output for an issue report. This doesn't fix the underlying crash for affected users, but it turns a ghost-crash bug into a self-diagnosing one so the next report includes actionable info. Closes-via-diag #7. === Fixes folded into the PR #9 merge === - src/scan_ips.rs: rand::thread_rng() held across an .await tripped the Send bound on the async fn. Scoped the rng in a block so it drops before the subsequent awaits. - src/scan_ips.rs: defend /0 and /32 CIDRs in cidr_to_ips and ip_in_cidr against 1u32 << 32 shift panic. All 36 unit tests pass.
1 parent 8651374 commit cc5f939

8 files changed

Lines changed: 118 additions & 6 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mhrv-rs"
3-
version = "0.7.1"
3+
version = "0.8.0"
44
edition = "2021"
55
description = "Rust port of MasterHttpRelayVPN -- DPI bypass via Google Apps Script relay with domain fronting"
66
license = "MIT"
@@ -46,6 +46,12 @@ flate2 = "1"
4646
directories = "5"
4747
futures-util = { version = "0.3", default-features = false, features = ["std"] }
4848

49+
# libc is only referenced for the RLIMIT_NOFILE bump on Unix (issue #8 —
50+
# OpenWRT routers ship a very low fd limit that gets hit quickly under normal
51+
# traffic). Already pulled in transitively via tokio, so zero new weight.
52+
[target.'cfg(unix)'.dependencies]
53+
libc = "0.2"
54+
4955
# Optional UI dep: only pulled in when --features ui is set.
5056
eframe = { version = "0.28", default-features = false, features = [
5157
"default_fonts",

assets/launchers/run.bat

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,40 @@ if errorlevel 1 (
1919
echo but HTTPS sites may show certificate warnings until the CA is trusted.
2020
)
2121

22-
if exist "mhrv-rs-ui.exe" (
23-
echo Starting mhrv-rs UI...
24-
start "" "mhrv-rs-ui.exe"
25-
) else (
22+
if not exist "mhrv-rs-ui.exe" (
2623
echo UI binary not found. Running CLI proxy instead.
2724
mhrv-rs.exe
25+
goto :eof
26+
)
27+
28+
echo.
29+
echo Starting mhrv-rs UI...
30+
echo (A new window should open. If nothing appears, the UI crashed — the
31+
echo error is shown in this terminal below. Take a screenshot of it and
32+
echo open an issue on github.)
33+
echo.
34+
35+
REM Run in-place (not via `start`) so if the UI dies on launch, its stderr
36+
REM and non-zero exit code are visible in this window. Previously we used
37+
REM `start "" "mhrv-rs-ui.exe"` which returns immediately and swallows any
38+
REM launch-time crash (issue #7).
39+
mhrv-rs-ui.exe
40+
set UI_EXIT=%ERRORLEVEL%
41+
if not "%UI_EXIT%"=="0" (
42+
echo.
43+
echo ---------------------------------------------------
44+
echo UI exited with error code %UI_EXIT%.
45+
echo.
46+
echo If this is the first time and you just saw the UI crash immediately,
47+
echo common causes on Windows are:
48+
echo - missing or outdated graphics drivers (try updating)
49+
echo - running inside RDP or a VM without GPU acceleration
50+
echo - antivirus blocking the exe — whitelist the folder and retry
51+
echo.
52+
echo Copy everything above and open an issue on:
53+
echo https://github.com/therealaleph/MasterHttpRelayVPN-RUST/issues
54+
echo ---------------------------------------------------
55+
pause
2856
)
2957

3058
endlocal

assets/openwrt/mhrv-rs.init

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ start_service() {
2424
procd_set_param stdout 1
2525
procd_set_param stderr 1
2626
procd_set_param file "$CONFIG"
27+
# Issue #8 — OpenWRT's default fd limit is tiny (often 1024 and sometimes
28+
# as low as 256 on constrained devices). A browser's parallel sub-resource
29+
# burst fills it in seconds and accept(2) starts returning EMFILE. 16k is
30+
# plenty for a local proxy and costs virtually no kernel memory.
31+
procd_set_param limits nofile="16384 16384"
2732
procd_close_instance
2833
}
2934

src/bin/ui.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const LOG_MAX: usize = 200;
2424

2525
fn main() -> eframe::Result<()> {
2626
let _ = rustls::crypto::ring::default_provider().install_default();
27+
mhrv_rs::rlimit::raise_nofile_limit_best_effort();
2728

2829
let shared = Arc::new(Shared::default());
2930
let (cmd_tx, cmd_rx) = std::sync::mpsc::channel::<Cmd>();

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub mod data_dir;
77
pub mod domain_fronter;
88
pub mod mitm;
99
pub mod proxy_server;
10+
pub mod rlimit;
1011
pub mod scan_ips;
1112
pub mod scan_sni;
1213
pub mod test_cmd;

src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ async fn main() -> ExitCode {
121121
// Install default rustls crypto provider (ring).
122122
let _ = rustls::crypto::ring::default_provider().install_default();
123123

124+
// Bump RLIMIT_NOFILE where possible — OpenWRT/Alpine hosts often ship a
125+
// default so low the proxy runs out of fds under normal browser load.
126+
mhrv_rs::rlimit::raise_nofile_limit_best_effort();
127+
124128
let args = match parse_args() {
125129
Ok(a) => a,
126130
Err(e) => {

src/rlimit.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//! Best-effort file descriptor limit bump on Unix.
2+
//!
3+
//! Context (issue #8): on OpenWRT routers — and some minimal Alpine / BSD
4+
//! installs — the default `RLIMIT_NOFILE` is so low (often 1024 or even
5+
//! 512) that a browser's burst of ~30 parallel subresource requests fills
6+
//! the limit within seconds. Once the limit is hit `accept(2)` returns
7+
//! `EMFILE` and the user sees:
8+
//!
9+
//! ERROR accept (socks): No file descriptors available (os error 24)
10+
//!
11+
//! This helper raises the soft limit up to the hard limit (without
12+
//! requiring root), so the user gets whatever headroom the kernel
13+
//! already allows them. Failures are logged and swallowed.
14+
15+
#[cfg(unix)]
16+
pub fn raise_nofile_limit_best_effort() {
17+
// Target: 16384 if the hard limit allows it, else whatever the hard
18+
// limit is. 16k matches what most modern desktop distros default to and
19+
// is plenty for a local proxy.
20+
const DESIRED: u64 = 16_384;
21+
22+
unsafe {
23+
let mut rl = libc::rlimit {
24+
rlim_cur: 0,
25+
rlim_max: 0,
26+
};
27+
if libc::getrlimit(libc::RLIMIT_NOFILE, &mut rl) != 0 {
28+
let err = std::io::Error::last_os_error();
29+
tracing::debug!("getrlimit(RLIMIT_NOFILE) failed: {}", err);
30+
return;
31+
}
32+
33+
// Already high enough? Leave it.
34+
let current = rl.rlim_cur as u64;
35+
let hard = rl.rlim_max as u64;
36+
if current >= DESIRED {
37+
return;
38+
}
39+
40+
let new_soft = DESIRED.min(hard);
41+
if new_soft <= current {
42+
return;
43+
}
44+
45+
rl.rlim_cur = new_soft as libc::rlim_t;
46+
if libc::setrlimit(libc::RLIMIT_NOFILE, &rl) != 0 {
47+
let err = std::io::Error::last_os_error();
48+
tracing::debug!(
49+
"setrlimit(RLIMIT_NOFILE) {} -> {} failed: {}",
50+
current,
51+
new_soft,
52+
err
53+
);
54+
return;
55+
}
56+
tracing::info!(
57+
"raised RLIMIT_NOFILE: {} -> {} (hard={})",
58+
current,
59+
new_soft,
60+
hard
61+
);
62+
}
63+
}
64+
65+
#[cfg(not(unix))]
66+
pub fn raise_nofile_limit_best_effort() {}

0 commit comments

Comments
 (0)