gogs: error: RPC failed; HTTP 502 curl 22 The requested URL returned error: 502 Bad Gateway

  • Gogs version (or commit ref): 0.10.18.0313
  • Git version: 2.11.1
  • Operating system: Ubuntu 16.04 64bits
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gogs.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist (usually found in log/gogs.log):
2017/03/18 00:43:07 [TRACE] Template: repo/home
2017/03/18 00:43:15 [TRACE] Session ID: 680247266044030b
2017/03/18 00:43:15 [TRACE] CSRF Token: XqrlvbmA3VRS46nV_Uufk3YAt_A6MTQ4OTgxMjE5NTE4NTY5ODg3Mg==
2017/03/18 00:43:15 [TRACE] Session ID: cba1c7a688bd14dc
2017/03/18 00:43:15 [TRACE] CSRF Token: PdAbkOr0oYgJst6rQpmkfuU1rbI6MTQ4OTgxMjE5NTQ4NzI2MTIyNA==

Description

Getting:

Mar 18 00:38:03 quark gogs[17459]: [Macaron] 2017-03-18 00:38:03: Completed POST /david/collantes.me.git/git-receive-pack 401 Unauthorized in 4.46717ms

On git client (Tower.app, macOS).

Full log:

Pushing to https://david@gits.quark.business/david/collantes.me.git
Counting objects: 31, done.
Delta compression using up to 8 threads.
Compressing objects:   3% (1/27)   
Compressing objects:   7% (2/27)   
Compressing objects:  11% (3/27)   
Compressing objects:  14% (4/27)   
Compressing objects:  18% (5/27)   
Compressing objects:  22% (6/27)   
Compressing objects:  25% (7/27)   
Compressing objects:  29% (8/27)   
Compressing objects:  33% (9/27)   
Compressing objects:  37% (10/27)   
Compressing objects:  40% (11/27)   
Compressing objects:  44% (12/27)   
Compressing objects:  48% (13/27)   
Compressing objects:  51% (14/27)   
Compressing objects:  55% (15/27)   
Compressing objects:  59% (16/27)   
Compressing objects:  62% (17/27)   
Compressing objects:  66% (18/27)   
Compressing objects:  70% (19/27)   
Compressing objects:  74% (20/27)   
Compressing objects:  77% (21/27)   
Compressing objects:  81% (22/27)   
Compressing objects:  85% (23/27)   
Compressing objects:  88% (24/27)   
Compressing objects:  92% (25/27)   
Compressing objects:  96% (26/27)   
Compressing objects: 100% (27/27)   
Compressing objects: 100% (27/27), done.
Writing objects:   3% (1/31)   
Writing objects:   6% (2/31)   
Writing objects:   9% (3/31)   
Writing objects:  12% (4/31)   
Writing objects:  16% (5/31)   
Writing objects:  19% (6/31)   
Writing objects:  22% (7/31)   
Writing objects:  25% (8/31)   
Writing objects:  29% (9/31)   
Writing objects:  32% (10/31)   
Writing objects:  35% (11/31)   
Writing objects:  38% (12/31)   
Writing objects:  41% (13/31)   
Writing objects:  48% (15/31)   
Writing objects:  51% (16/31)   
Writing objects:  54% (17/31)   
Writing objects:  58% (18/31)   
Writing objects:  61% (19/31)   
Writing objects:  64% (20/31)   
Writing objects:  67% (21/31)   
Writing objects:  70% (22/31)   
Writing objects:  74% (23/31)   
Writing objects:  77% (24/31)   
Writing objects:  80% (25/31)   
Writing objects:  83% (26/31)   
Writing objects:  87% (27/31)   
Writing objects:  90% (28/31)   
Writing objects:  93% (29/31)   
Writing objects:  96% (30/31)   
Writing objects: 100% (31/31)   
Writing objects: 100% (31/31), 359.70 KiB | 0 bytes/s, done.
Total 31 (delta 3), reused 0 (delta 0)
POST git-receive-pack (368506 bytes)
error: RPC failed; HTTP 502 curl 22 The requested URL returned error: 502 Bad Gateway
fatal: The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly
Everything up-to-date

When trying to push a commit. I can commit one small file, no problems. If I try to add several files, or directories, the error occurs. From server’s /var/log/syslog:

Mar 18 00:50:04 quark gogs[17459]: [Macaron] 2017-03-18 00:50:04: Started GET /david/collantes.me.git/info/refs?service=git-receive-pack for XXX.XXX.XXX.XXX
Mar 18 00:50:04 quark gogs[17459]: [Macaron] 2017-03-18 00:50:04: Completed GET /david/collantes.me.git/info/refs?service=git-receive-pack 200 OK in 18.748727ms
Mar 18 00:50:04 quark gogs[17459]: [Macaron] 2017-03-18 00:50:04: Started POST /david/collantes.me.git/git-receive-pack for XXX.XXX.XXX.XXX
Mar 18 00:50:04 quark gogs[17459]: [Macaron] 2017-03-18 00:50:04: Completed POST /david/collantes.me.git/git-receive-pack 401 Unauthorized in 3.706604ms

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 48 (39 by maintainers)

Most upvoted comments

Like @netlander the workaround of bypassing the Apache proxy worked for me. It was crashing at that step: “POST git-receive-pack (7200216 bytes)”, but this works normally without the proxy.

Might well be related to the 401: with the Apache mod_proxy, I did not receive an authentication request, but I received one without the proxy and had to type user/password for the commit to be accepted.

Apache error log (multiple identical lines):

[Sat Jan 12 09:12:33.710124 2019] [proxy:error] [pid 25787] (32)Broken pipe: [client 37.58.212.212:59962] AH01084: pass request body failed to 127.0.0.1:3000 (127.0.0.1)
[Sat Jan 12 09:12:33.710162 2019] [proxy_http:error] [pid 25787] [client 37.58.212.212:59962] AH01097: pass request body failed to 127.0.0.1:3000 (127.0.0.1) from 37.58.212.212 ()

Gogs log/hooks/post-receive.log (9:20 is without the proxy, nothing visible at 9:12 with the proxy):

2019/01/12 09:20:41 [ERROR] [...ogs/models/action.go:493 CommitRepoAction()] UpdateIssuesCommit: invalid issue reference [ref: 09/01/2019]

Other log/hooks/* files are touched but empty

Portion of the log/gogs.log which appears relevant, without the proxy:

2019/01/12 09:20:41 [TRACE] HTTPGit - Authenticated user: fgm
2019/01/12 09:20:41 [TRACE] Session ID: d8376360d674a0ea
2019/01/12 09:20:41 [TRACE] CSRF Token: FKyzeZELo1j4eoGE-TKp3yDmyc06MTU0NzI4NDg0MTU0MjMxMjM2MA==
2019/01/12 09:20:41 [TRACE] Detected encoding: UTF-8 (fast)
2019/01/12 09:20:41 [TRACE] Template: repo/home
2019/01/12 09:20:41 [TRACE] Session ID: 9e0fc1184eb4970b
2019/01/12 09:20:41 [TRACE] CSRF Token: M0fhCH0kbQAhgfPKdmaXSga1DPk6MTU0NzI4NDg0MTkxMjIwMDAwOA==
2019/01/12 09:20:41 [TRACE] TriggerTask 'assets__prague2013_blocks/blocks-1-8' by 'fgm'
2019/01/12 09:20:41 [TRACE] DeliverHooks [repo_id: 112]
2019/01/12 09:20:41 [TRACE] AddTestPullRequestTask [head_repo_id: 112, head_branch: blocks-1-8]: finding pull requests
2019/01/12 09:20:41 [TRACE] AddTestPullRequestTask [base_repo_id: 112, base_branch: blocks-1-8]: finding pull requests

More interestingly, updating my HTTPS Vhost to look like this, as suggested on https://httpd.apache.org/docs/2.4/en/mod/mod_proxy.html#envsettings , fixed the issue for me. It causes the browser to ask for credentials (triggering keychain access in macOS), and succeeds:

  ProxyPreserveHost On
  ProxyRequests off
  ProxyPass / http://127.0.0.1:3000/
  ProxyPassReverse / http://127.0.0.1:3000/
  SetEnv force-proxy-request-1.0 1
  SetEnv proxy-nokeepalive 1

This might suggest a problem with HTTP/1.1 keepalive handling in Gogs or its dependencies.

I had this error with Gitlab behind an Nginx proxy with pushing large files.

$ git push origin master
warning: redirecting to http://xxxx.xxxx.xxx/xxxx/xxxx.git/
Uploading LFS objects: 100% (2/2), 408 MB | 0 B/s, done                                                                                                                                                                                                 
Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 6 threads
Compressing objects: 100% (8/8), done.
Writing objects: 100% (8/8), 386.08 MiB | 8.74 MiB/s, done.
Total 8 (delta 0), reused 0 (delta 0)
error: RPC failed; HTTP 502 curl 22 The requested URL returned error: 502
fatal: the remote end hung up unexpectedly
fatal: the remote end hung up unexpectedly
Everything up-to-date

This was my solution for nginx based on @fgm and the keepalive clue: (SSL terminated at a higher layer, this is for the internal LB in front of docker containers) Narrowed down the issue to proxy_http_version, keepalive and removing the connection header.

http {
...
    upstream gitlab {
        keepalive 100;
        server 00.000.0.0:8080;
    }

server {
        listen 80;
        server_name gitlab.entouch.jp;

        location / {
            add_header Strict-Transport-Security "max-age=15768000;";
            keepalive_timeout 120s;

            proxy_read_timeout 3600s;
            proxy_http_version 1.1;

            # Remove Connection header, client might send "close" to close a keepalive connection
            proxy_set_header Connection "";
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto https;
            proxy_set_header X-Forwarded-Host $host:$server_port;
            proxy_set_header X-Forwarded-Server $host;

            proxy_pass http://gitlab/;
        }
    }
...
}

Something else that can help to narrow down the cause: GIT_CURL_VERBOSE=1 GIT_TRACE=1 git push origin master

Ran also into this issue today. We have several repos, and only one cannot be pushed anymore. Using apache2.2, gogs 0.11.34 and reverse proxy. SetEnv proxy-sendcl 1 didn’t help. Setting the git http.postBuffer to 524288000 didn’t help.

The workaround that helped was to bypass the proxy. So I changed gogs to listen on the lan ip and change the remote url to connect to port 3000 directly. Then I could push, revert above changes, and newly pushed commits are working again.

So this seems to be a strange combination of things. The problematic push had 5 commits, maybe it’s a size problem?

@Unknwon installed Caddy, no problems. I am assuming it was an Apache, a mod_proxy or a mod_proxy_http problem. Weird it did not presented itself with other applications, but gogs. Shrugs.

Another tidbit. I installed Gitea (the bastard fork 😂) and it works fine, so it seems the issue is related to Gogs.