Skip to content

Tunnel Node behind NGINX(and also directly) is very slow #950

Open

Description

@behnamgolds

Hi,
I'v setup the tunnel node on my VPS(France) , I have nginx with letsencrypt certificate in place and it is working and receives requests as expected, but it is very slow (below 30 Kilobytes/s) compared to my other apps_script and cloudflare worker setup.
I was checking the logs of my nginx setup today(/var/log/nginx/error.log) where I see lots of warnings like this:

[warn] 6736#6736: *813 an upstream response is buffered to a temporary file /var/lib/nginx/tmp/proxy/5/04/0000000045 while reading upstream, client: 34.116.28.165, server: fwd.mydomain.com, request: "POST /tunnel/batch HTTP/1.1", upstream: "http://127.0.0.1:8080/tunnel/batch", host: "fwd.mydomain.com"

and in my mhrv-rs(version 1.9.18) I see error logs like this:

ERROR batch failed (script AKfycbx-): got the v1.8.0 decoy/placeholder body — could be (1) AUTH_KEY mismatch between mhrv-rs config and Code.gs (run a direct curl probe against the deployment to verify), (2) Apps Script execution timeout or per-100s quota tear (try lowering parallel_concurrency in config), (3) Apps Script internal hiccup (transient, retry next batch), or (4) ISP-side response truncation (#313 pattern, try a different google_ip). To distinguish (1) from the rest: set DIAGNOSTIC_MODE=true at the top of Code.gs + redeploy as new version — only AUTH_KEY mismatch returns this body in diagnostic mode.

I also tried the set up without nginx and on the default 8080 port (my.vps.ip.address:8080). I don't think it is related to nginx since using the tunnel node directly gives the same results, but I thought maybe there is something useful in the nginx log above .

I have three seperate Code.gs deployments(different accounts) in place all with the same config, I double checked the AUTH_KEY, and they all match my config.js file. And I do not know about another google_ip that works (just the one that nslookup returns) . But I don't think it is related to the google_ip or google sni either, since my apps_script and cloudflare setups use the same ip and sni. My guess is there is something wrong between the Code.gs and my vps.

Some rare occasions I see a spike in loading speed around 2 or 3 Mgabytes/Sec but quickly it slumps below 30 Kilobytes/s .

Do you know what the problem is and how to solve it?

Activity

  1. ehsan272727 commented on May 9, 2026

    @ehsan272727

    I also did the VPS method fo Full tunnel mode and it just doesn't work

  2. behnamgolds commented on May 9, 2026

    @behnamgolds
    Author

    I also did the VPS method fo Full tunnel mode and it just doesn't work

    @ehsan272727 create a new issue and provide more info (logs, versions, etc..) .
    There is a big green button at the top right corner of this page.

    Image

  3. therealaleph commented on May 9, 2026

    @therealaleph
    Owner

    Reviewed via Anthropic Claude.

    @behnamgolds — useful data point. Two separate things in your report:

    1. nginx proxy_buffering warning (the temp-file write):
    That warning is informational, not the root cause of the 30 KB/s. It means the tunnel-node response exceeded proxy_buffer_size (default 4-8 KB depending on platform) so nginx spilled to disk. For a relay where every batch can be up to 32 MiB (after v1.9.16's BATCH_RESPONSE_BUDGET), that's expected. To eliminate it, increase nginx's buffer config for this server block:

    server {
      # ... your existing config ...
    
      location /tunnel/ {
        proxy_pass http://127.0.0.1:8080;
        proxy_http_version 1.1;
        proxy_request_buffering off;          # stream client → upstream
        proxy_buffering off;                  # stream upstream → client
        proxy_max_temp_file_size 0;           # disable disk spill entirely
        proxy_read_timeout 360s;              # match Apps Script's 6-min cap
        proxy_send_timeout 360s;
        client_max_body_size 64m;             # batch can be ~32 MiB after base64
      }
    }

    The two proxy_*_buffering off directives are the important ones — without them, nginx sits on the entire batch before forwarding, defeating the point of streaming.

    2. The v1.8.0 decoy/placeholder body (the one you got even WITHOUT nginx):
    This is the actual perf killer. Code.gs returns this body when its UrlFetchApp.fetch(TUNNEL_SERVER_URL) call throws an exception — timeout, connection refused, response too large, etc. mhrv-rs's error message lists 4 possible causes:

    Given your specific setup (nginx, France VPS, 30 KB/s, 3 deployments), the likely cause is response-size: Apps Script UrlFetchApp has a hard 50 MiB response body cap. If your tunnel-node returns a batch larger than 50 MiB, UrlFetchApp throws, Code.gs's try/catch sends the decoy. v1.9.16 added a 32 MiB total-batch budget on the tunnel-node side specifically to prevent this; if you're on v1.9.18 + recent tunnel-node:latest Docker image, that should hold.

    Diagnostic steps that would narrow it down:

    1. Direct curl probe against your deployment (not via mhrv-rs):

      curl -v -X POST https://script.google.com/macros/s/<deployment>/exec \
        -H "Content-Type: application/json" \
        -d '{"k":"YOUR_AUTH_KEY","ops":[{"op":"ping"}]}'
      • If you get JSON {"results":[{"r":"pong"}]} → AUTH_KEY is fine and Code.gs ↔ tunnel-node is reachable. The slowness is somewhere in the streaming.
      • If you get the decoy HTML → AUTH_KEY mismatch OR tunnel-node URL wrong inside Code.gs (TUNNEL_SERVER_URL constant).
    2. Watch tunnel-node logs while running mhrv-rs:

      docker logs -f mhrv-tunnel

      When the slowdown / decoy error fires in mhrv-rs, what's tunnel-node's log line at the same moment? Is it returning a successful batch JSON (size?) or erroring?

    3. Pull tunnel-node:latest again — you might be on an older image. v1.9.16+ has the BATCH_RESPONSE_BUDGET fix for updating steam on full mode #863:

      docker pull ghcr.io/therealaleph/mhrv-tunnel-node:latest
      docker stop mhrv-tunnel && docker rm mhrv-tunnel
      docker run -d --name mhrv-tunnel --restart unless-stopped -p 8080:8080 \
        -e TUNNEL_AUTH_KEY="$SECRET" ghcr.io/therealaleph/mhrv-tunnel-node:latest
    4. France VPS routing: Apps Script runs on Google's network. If your tunnel-node is in France and Apps Script's regional edge (often US/EU) routes to it through congested transit, you'll see slow batches. The مشکل حالت فول تانل vps از نسخه ۱.۹.۱۵ به بعد #924 thread has a hypothesis that nginx-as-reverse-proxy interacts badly with h2 inner connections in v1.9.15+ — could be relevant here even on the without-nginx case if there's some intermediate Cloudflare / OVH / Hetzner network policy.

    Pinning #924 as the canonical Full Tunnel slowness tracker. Could you post:

    • nginx config (redacted) — or note that you tested without it
    • tunnel-node Docker image SHA: docker inspect mhrv-tunnel | grep -i image
    • mhrv-rs log around the decoy error (5 lines before, 5 after) so we can see which sites / batch sizes are correlated with the failures

    Leaving open as one of the canonical Full Tunnel slowness reports. Thanks for the detailed nginx logs — exactly what we needed.

  4. Stazzical commented on May 10, 2026

    @Stazzical

    would adding an option to disable H2 connections be helpful somehow to see if that's the cause of slowness?

  5. mirbaagheri commented on May 10, 2026

    @mirbaagheri
  6. behnamgolds commented on May 11, 2026

    @behnamgolds
    Author

    Sorry for the delay, since script.google.com is not available directly and I wanted to rule out the problems related to using a proxy , had to go somewhere that script.google.com is reachable.

    I tested the curl command, but it gives http Code 302 (moved Temporarily) :

    curl -4 -v -X POST https://script.google.com/macros/s/<MyDeploymentID>/exec \
      -H "Content-Type: application/json" \
      -d '{"k":"iethoh4aishiukee","ops":[{"op":"ping"}]}'
    
    * Host script.google.com:443 was resolved.
    * IPv6: (none)
    * IPv4: 142.251.38.238
    *   Trying 142.251.38.238:443...
    * ALPN: curl offers h2,http/1.1
    * TLSv1.3 (OUT), TLS handshake, Client hello (1):
    * SSL Trust Anchors:
    *   CAfile: /etc/ssl/certs/ca-certificates.crt
    * TLSv1.3 (IN), TLS handshake, Server hello (2):
    * TLSv1.3 (IN), TLS change cipher, Change cipher spec (1):
    * TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
    * TLSv1.3 (IN), TLS handshake, Certificate (11):
    * TLSv1.3 (IN), TLS handshake, CERT verify (15):
    * TLSv1.3 (IN), TLS handshake, Finished (20):
    * TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
    * TLSv1.3 (OUT), TLS handshake, Finished (20):
    * SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384 / X25519MLKEM768 / id-ecPublicKey
    * ALPN: server accepted h2
    * Server certificate:
    *   subject: CN=*.google.com
    *   start date: Apr 20 08:35:15 2026 GMT
    *   expire date: Jul 13 08:35:14 2026 GMT
    *   issuer: C=US; O=Google Trust Services; CN=WE2
    *   Certificate level 0: Public key type EC/prime256v1 (256/128 Bits/secBits), signed using ecdsa-with-SHA256
    *   Certificate level 1: Public key type EC/prime256v1 (256/128 Bits/secBits), signed using ecdsa-with-SHA384
    *   Certificate level 2: Public key type EC/secp384r1 (384/192 Bits/secBits), signed using ecdsa-with-SHA384
    *   subjectAltName: "script.google.com" matches cert's "*.google.com"
    * OpenSSL verify result: 0
    * SSL certificate verified via OpenSSL.
    * Established connection to script.google.com (142.251.38.238 port 443) from 172.25.1.2 port 53800 
    * using HTTP/2
    * [HTTP/2] [1] OPENED stream for https://script.google.com/macros/s/<MyDeploymentID>/exec
    * [HTTP/2] [1] [:method: POST]
    * [HTTP/2] [1] [:scheme: https]
    * [HTTP/2] [1] [:authority: script.google.com]
    * [HTTP/2] [1] [:path: /macros/s/<MyDeploymentID>/exec]
    * [HTTP/2] [1] [user-agent: curl/8.20.0]
    * [HTTP/2] [1] [accept: */*]
    * [HTTP/2] [1] [content-type: application/json]
    * [HTTP/2] [1] [content-length: 46]
    > POST /macros/s/<MyDeploymentID>/exec HTTP/2
    > Host: script.google.com
    > User-Agent: curl/8.20.0
    > Accept: */*
    > Content-Type: application/json
    > Content-Length: 46
    > 
    * upload completely sent off: 46 bytes
    * TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
    * TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
    < HTTP/2 302 
    < content-type: text/html; charset=UTF-8
    < access-control-allow-origin: *
    < cache-control: no-cache, no-store, max-age=0, must-revalidate
    < pragma: no-cache
    < expires: Mon, 01 Jan 1990 00:00:00 GMT
    < date: Mon, 11 May 2026 06:13:29 GMT
    < location: https://script.googleusercontent.com/macros/echo?user_content_key=<A_Long_String>&lib=<A_Short_String>< x-content-type-options: nosniff
    < x-frame-options: SAMEORIGIN
    < content-security-policy: frame-ancestors 'self'
    < x-xss-protection: 1; mode=block
    < server: GSE
    < alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
    < accept-ranges: none
    < vary: Accept-Encoding
    < 
    <HTML>
    <HEAD>
    <TITLE>Moved Temporarily</TITLE>
    </HEAD>
    <BODY BGCOLOR="#FFFFFF" TEXT="#000000">
    <!-- GSE Default Error -->
    <H1>Moved Temporarily</H1>
    The document has moved <A HREF="https://script.googleusercontent.com/macros/echo?user_content_key=<A_Very_Long_String>&amp;lib=<A_Short_String>">here</A>.
    </BODY>
    </HTML>
    * Connection #0 to host script.google.com:443 left intact
    

    My guess is something has changed google side, like flagging my scripts as suspocious since I opened this issue. My other configs (plain Code.gs and CFW) do not work either.

  7. behnamgolds commented on May 11, 2026

    @behnamgolds
    Author

    I opened this link provided in the output above in my browser:

    https://script.googleusercontent.com/macros/echo?user_content_key=<A_Very_Long_String>&amp;lib=<A_Short_String>
    

    the result:

    <!DOCTYPE html><html><head><title>Web App</title></head><body><p>The script completed but did not return anything.</p></body></html>
    
  8. behnamgolds commented on May 11, 2026

    @behnamgolds
    Author

    And I forgot to say , nothing reaches nginx/tunnel-node right now, but I dont think it is relevant right now.

  9. behnamgolds commented on May 11, 2026

    @behnamgolds
    Author

    In the mean time I ignored the curl since it is not working as expected, I changed the nginx conf as you suggested (I had http2 mode on too so I changed it to off). I don't use docker, just downloaded the lates release 1.9.21 for the client and compliled the tunne-node again.

    this is my nginx.conf:

    user nginx;
    worker_processes auto;
    error_log /var/log/nginx/error.log notice;
    pid /run/nginx.pid;
    
    
    # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
    
    events {
        worker_connections 1024;
    }
    
    http {
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
        access_log  /var/log/nginx/access.log  main;
    
        sendfile            on;
        tcp_nopush          on;
        keepalive_timeout   65;
        types_hash_max_size 4096;
    
        include             /etc/nginx/mime.types;
        default_type        application/octet-stream;
    
        server {
    	listen       443 ssl;
    	http2 	     off;
    	server_name  fwd.mydomain.com;
    
            ssl_certificate /etc/letsencrypt/live/fwd.mydomain.com/fullchain.pem; # managed by Certbot
            ssl_certificate_key /etc/letsencrypt/live/fwd.mydomain.com/privkey.pem; # managed by Certbot
            include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
            ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    
            location /tunnel/ {
    	    proxy_http_version 1.1;
                proxy_request_buffering off;          # stream client → upstream
                proxy_buffering off;                  # stream upstream → client
                proxy_max_temp_file_size 0;           # disable disk spill entirely
                proxy_read_timeout 360s;              # match Apps Script's 6-min cap
                proxy_send_timeout 360s;
                client_max_body_size 64m;             # batch can be ~32 MiB after base64
                proxy_pass http://127.0.0.1:8080;
            }
        }
    }
    

    No warinns related to nginx about writing buffer to disk appears anymore. but the slowness is still there.

    this is some lines of nginx access.log :

    34.116.28.67 - - [11/May/2026:11:28:06 +0330] "POST /tunnel/batch HTTP/1.1" 200 5753 "-" "Mozilla/5.0 (compatible; Google-Apps-Script; beanserver; +https://script.google.com; id: UAEmdDd_K-ThwS7MFYwxi9BG3FQJGprw8jw)" "78.38.38.254"
    34.116.28.67 - - [11/May/2026:11:28:11 +0330] "POST /tunnel/batch HTTP/1.1" 200 65 "-" "Mozilla/5.0 (compatible; Google-Apps-Script; beanserver; +https://script.google.com; id: UAEmdDd8sr6oLjwbl7qotCyGwyKPdMe3K-mk)" "78.38.38.254"
    

    This is a chunk of the tunnel-node log(removed the first part of each lines and kept the interesting parts):

    INFO tunnel_node: session ee20fc78-6778-4530-9539-edd99e8b81d3 -> httpbin.org:443 (connect_data)
    INFO tunnel_node: session ee20fc78-6778-4530-9539-edd99e8b81d3 closed by client
    INFO tunnel_node: session 9ba511d7-cba4-40fb-89f7-234d5f054903 -> httpbin.org:443 (connect_data)
    INFO tunnel_node: session 9ba511d7-cba4-40fb-89f7-234d5f054903 closed by client
    INFO tunnel_node: session bfb4ca25-2cb9-458e-a0eb-50ba6114ed94 -> httpbin.org:443 (connect_data)
    INFO tunnel_node: session bfb4ca25-2cb9-458e-a0eb-50ba6114ed94 closed by client
    INFO tunnel_node: session 3e3d2135-12f5-4ba5-a6f7-813378a62568 -> httpbin.org:443 (connect_data)
    INFO tunnel_node: session 3e3d2135-12f5-4ba5-a6f7-813378a62568 closed by client
    INFO tunnel_node: session c1a014b4-0bea-459f-bb6e-da9bb48ceda4 -> httpbin.org:443 (connect_data)
    

    The interesting part in the log is closed by client while I tried to open httpbin

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