go-gitea / gitea

Git with a cup of tea! Painless self-hosted all-in-one software development service, including Git hosting, code review, team collaboration, package registry and CI/CD
https://gitea.com
MIT License
44.6k stars 5.45k forks source link

git-receive-pack returns 404 if mysql connection closed by mysql server #4700

Closed SagePtr closed 5 years ago

SagePtr commented 6 years ago

Description

If mysql connection is closed by mysql server (due to activity timeout) - git-receive-pack returns 404 and git client shows message repo doesn't exist.

How to reproduce:

  1. Configure mysql wait_timeout and interactive_timeout to something small (in my example it was 60 seconds).
  2. Do git push (it will be successful probably)
  3. Wait for timeout to happen (in my example, 60 seconds plus few seconds more)
  4. Do git push again. Result will be fatal: repository 'http://localhost:3000/username/reponame.git/' not found returned by git client.
  5. Do git push one more time. Now it will be successful.

Logs

step 2 (successful)

[Macaron] 2018-08-14 11:53:02: Started GET /username/reponame.git/info/refs?service=git-receive-pack for [::1]
[Macaron] 2018-08-14 11:53:02: Completed GET /username/reponame.git/info/refs?service=git-receive-pack 401 Unauthorized in 8.0005ms
[Macaron] 2018-08-14 11:53:03: Started GET /username/reponame.git/info/refs?service=git-receive-pack for [::1]
[Macaron] 2018-08-14 11:53:03: Completed GET /username/reponame.git/info/refs?service=git-receive-pack 200 OK in 227.0249ms

step 4 (failed)

[Macaron] 2018-08-14 11:54:18: Started GET /username/reponame.git/info/refs?service=git-receive-pack for [::1]
[mysql] 2018/08/14 11:54:18 packets.go:36: read tcp 127.0.0.1:61929->127.0.0.1:3306: wsarecv: An established connection was aborted by the software in your host machine.
[Macaron] 2018-08-14 11:54:18: Completed GET /username/reponame.git/info/refs?service=git-receive-pack 404 Not Found in 11.0006ms

step 5 (successful)

[Macaron] 2018-08-14 11:54:23: Started GET /username/reponame.git/info/refs?service=git-receive-pack for [::1]
[Macaron] 2018-08-14 11:54:23: Completed GET /username/reponame.git/info/refs?service=git-receive-pack 401 Unauthorized in 99.0056ms
[Macaron] 2018-08-14 11:54:24: Started GET /username/reponame.git/info/refs?service=git-receive-pack for [::1]
[Macaron] 2018-08-14 11:54:24: Completed GET /username/reponame.git/info/refs?service=git-receive-pack 200 OK in 223.0177ms

Expected behavior

If established connection to mysql was closed and cannot be reused for query, that query should be retried at least once rather then failing at all. And if there is error, this error should be one of 5** errors (indicating server error), not 404.

Probably this won't ever happen in real life because MySQL default timeout is 8 hours and between these 8 hours mysql connection will be reused multiple times.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.

stale[bot] commented 5 years ago

This issue has been automatically closed because of inactivity. You can re-open it if needed.