gitea: 1.18.0 on Windows error: can not resolve localhost, ! [remote rejected] master -> master (pre-receive hook declined)

Description

Save your time:

1.17.4 is good but 1.18.0 has a bug: 
dial tcp: lookup localhost on 114.114.114.114:53: no such host

Detailed:

I use 1.18.0 Gitea, when I push files, occur:

$ git push
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 20 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 305 bytes | 305.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: Gitea: Internal Server Error
remote: Unable to contact gitea: Post "http://localhost:3000/api/internal/hook/pre-receive/jinyang/test": dial tcp: lookup localhost on 114.114.114.114:53: no such host
To http://localhost:3000/jinyang/test.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'http://localhost:3000/jinyang/test.git'

I searched some related issues but finally failed to fix this.

Then I installed 1.17.4 Gitea and this problem gone.

Then I re-installed 1.18.0 Gitea again and still can not push.

Gitea Version

1.18.0

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

NA

Git Version

git version 2.39.0.windows.2

Operating System

WINDOWS 11

How are you running Gitea?

download binary on https://dl.gitea.io/gitea [gitea-1.18.0-windows-4.0-amd64.exe]

download it on my PC and move it to D:\Program Files\Gitea, then double click the gitea-1.18.0-windows-4.0-amd64.exe

Database

SQLite

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 28 (18 by maintainers)

Commits related to this issue

Most upvoted comments

I think this issue should be re-opened and it needs a patch.

To make the workaround prominent, I didn’t say too much about my guess before.

Here is my opinion of this bug:

How it happens?

Gitea (Golang net package) can not resolve host localhost.

Golang’s net package need correct /etc/hosts and /etc/nsswitch.conf to resolve domains correctly. If anything is broken, it may not resolve some domains. On Windows, it also depends on C:\Windows\System32\Drivers\etc\hosts file

Why there are so many reports recently?

Possibility 1

Alpine / Go or Go for Windows changed some behaviors which conflict with user’s environment, then Golang’s net package doens’t work well in some rare cases (no evidence yet). But since some users reported that 1.17.x works but 1.18.x fails, maybe there is something changed.

Possibility 2

Many users’ systems were already broken, they messed up their hosts file, they might have deleted the 127.0.0.1 localhost line. I know a lot of such users.

Before, some public DNS servers can also resolve localhost, for example, there is still one now:

$ dig localhost @223.5.5.5
;; ANSWER SECTION:
localhost.		2495	IN	A	127.0.0.1

Recently some public DNS servers might have stopped such non-standard behavior, if they do not resolve localhost anymore, the users with broken localhost definition will encounter the problem.

So, some users with broken hosts files can get Gitea working before, but get errors now.

The patch

Approach 1

Use 127.0.0.1 instead of localhost for the default value of LOCAL_ROOT_URL

  • Pros

    • 127.0.0.1 is the de-facto standard loopback IP, it should exist in every OS
    • won’t be affected by Host OS/Alpine/Golang anymore (in most cases)
    • even if the user’s hosts file is broken, it still works
  • Cons

    • In a pure IPv6 network, the 127.0.0.1 may not exist, but the pure IPv6 network should be pretty rarer than broken hosts files, and a user with pure IPv6 must be an experienced user, they should be able to set LOCAL_ROOT_URL to a IPv6 loopback without any question.

Approach 2

Find the root case why 1.17.x works but 1.18.x doesn’t.

Update: maybe it’s a Go 1.19 bug: https://github.com/golang/go/issues/53490

And: https://tip.golang.org/doc/go1.19#net

The net package now has initial support for the netgo build tag on Windows. When used, the package uses the Go DNS client (as used by Resolver.PreferGo) instead of asking Windows for DNS results. The upstream DNS server it discovers from Windows may not yet be correct with complex system network configurations, however.

Removing the netgo tag from Windows build may resolve the problem.

Approach 3

Try to resolve localhost at startup, report fatal errors if the resolution fails.

I think it’s related to this Go bug:

And: https://tip.golang.org/doc/go1.19#net

The net package now has initial support for the netgo build tag on Windows. When used, the package uses the Go DNS client (as used by Resolver.PreferGo) instead of asking Windows for DNS results. The upstream DNS server it discovers from Windows may not yet be correct with complex system network configurations, however.


Removing the netgo tag from Windows build may resolve the problem.

For others seeing this conversation the LOCAL_ROOT_URL is in the [server] section of the app.ini and it must be added there.