HOST setting in app.ini incorrectly used. #10792

Closed
opened 2025-11-02 09:18:17 -06:00 by GiteaMirror · 5 comments
Owner

Originally created by @lelanthran on GitHub (May 5, 2023).

Description

My app.ini file has the following line:

HOST = /var/run/postgresql/.s.PGSQL.27541

Gitea logs the following messages to syslog:

May 5 20:36:53 small-repo gitea[37607]: 2023/05/05 20:36:53 routers/common/db.go:34:InitDBEngine() [E] ORM engine initialization attempt #1/10 failed. Error: dial unix /var/run/postgresql/.s.PGSQL.27541/.s.PGSQL.5432: connect: not a directory

The documentation (over here) says:

HOST: 127.0.0.1:3306: Database host address and port or absolute path for unix socket [mysql, postgres] (ex: /var/run/mysqld/mysqld.sock).

When I change the app.ini to have only the directory name, it doesn't find the file .s.PGSQL.27541 (because postgresql creates the socket file based on the port that it is listening on, which in my installation is not the standard port).

HOST = /var/run/postgresql

Now the logs say:

May 5 20:44:51 small-repo gitea[38047]: 2023/05/05 20:44:51 routers/common/db.go:34:InitDBEngine() [E] ORM engine initialization attempt #1/10 failed. Error: dial unix /var/run/postgresql/.s.PGSQL.5432: connect: no such file or directory

As a temporary fix I have soft-linked the expected filename (.s.PGSQL.5432) to the actual file (.s.PGSQL.27541), and it works as expected when the file .s.PGSQL.5432 is soft-linked to the file created by postgresql.

The expected behaviour is what the documentation says, that the HOST value is used as-is, and gitea does not append the hardcoded .s.PGSQL.5432 to it.

The hardcoded value appears to be returned by parsePostgreSQLHostPort() in the port variable. The pq library function open() receives a string, and builds the final string by appending .s.PGSQL.<port>, which results in the incorrect filename being used.

Gitea Version

1.19.3

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

n/a

Screenshots

n/a

Git Version

n/a

Operating System

Bullseye

How are you running Gitea?

Bullseye repo.

Database

PostgreSQL

Originally created by @lelanthran on GitHub (May 5, 2023). ### Description My app.ini file has the following line: `HOST = /var/run/postgresql/.s.PGSQL.27541` Gitea logs the following messages to syslog: `May 5 20:36:53 small-repo gitea[37607]: 2023/05/05 20:36:53 routers/common/db.go:34:InitDBEngine() [E] ORM engine initialization attempt #1/10 failed. Error: dial unix /var/run/postgresql/.s.PGSQL.27541/.s.PGSQL.5432: connect: not a directory` The documentation ([over here](https://docs.gitea.io/en-us/administration/config-cheat-sheet/#database-database)) says: `HOST: 127.0.0.1:3306: Database host address and port or absolute path for unix socket [mysql, postgres] (ex: /var/run/mysqld/mysqld.sock).` When I change the app.ini to have only the directory name, it doesn't find the file `.s.PGSQL.27541` (because postgresql creates the socket file based on the port that it is listening on, which in my installation is not the standard port). `HOST = /var/run/postgresql` Now the logs say: `May 5 20:44:51 small-repo gitea[38047]: 2023/05/05 20:44:51 routers/common/db.go:34:InitDBEngine() [E] ORM engine initialization attempt #1/10 failed. Error: dial unix /var/run/postgresql/.s.PGSQL.5432: connect: no such file or directory` As a temporary fix I have soft-linked the expected filename (`.s.PGSQL.5432`) to the actual file (`.s.PGSQL.27541`), and it works as expected when the file `.s.PGSQL.5432` is soft-linked to the file created by postgresql. The expected behaviour is what the documentation says, that the HOST value is used as-is, and gitea does not append the hardcoded `.s.PGSQL.5432` to it. The hardcoded value appears to be returned by `parsePostgreSQLHostPort()` in the `port` variable. The `pq` library function `open()` receives a string, and builds the final string by appending `.s.PGSQL.<port>`, which results in the incorrect filename being used. ### Gitea Version 1.19.3 ### Can you reproduce the bug on the Gitea demo site? No ### Log Gist n/a ### Screenshots n/a ### Git Version n/a ### Operating System Bullseye ### How are you running Gitea? Bullseye repo. ### Database PostgreSQL
GiteaMirror added the hacktoberfesttype/docsgood first issuetype/bug labels 2025-11-02 09:18:18 -06:00
Author
Owner

@DanieleAurilio commented on GitHub (May 27, 2023):

Hi @lelanthran ,
have you tried to use HOST = /var/run/postgresql:27541 ?
Here https://github.com/go-gitea/gitea/blob/main/modules/setting/database.go#L150 seems to use a custom port if declared after the ":".

@DanieleAurilio commented on GitHub (May 27, 2023): Hi @lelanthran , have you tried to use `HOST = /var/run/postgresql:27541` ? Here https://github.com/go-gitea/gitea/blob/main/modules/setting/database.go#L150 seems to use a custom port if declared after the ":".
Author
Owner

@lunny commented on GitHub (Jul 27, 2023):

Is this resolved?

@lunny commented on GitHub (Jul 27, 2023): Is this resolved?
Author
Owner

@lelanthran commented on GitHub (Aug 6, 2023):

Sorry about taking so long to reply; I haven't tried the suggestion from @DanieleAurilio, I will try it and report back tomorrow.

My feeling is that, even if that works, that is different to what the documentation says should happen. If it works, maybe a new issue to change the documentation to match the behaviour?

@lelanthran commented on GitHub (Aug 6, 2023): Sorry about taking so long to reply; I haven't tried the suggestion from @DanieleAurilio, I will try it and report back tomorrow. My feeling is that, even if that works, that is different to what the documentation says should happen. If it works, maybe a new issue to change the documentation to match the behaviour?
Author
Owner

@lelanthran commented on GitHub (Aug 17, 2023):

Hello all, @DanieleAurilio, @lunny

The suggestion from @DanieleAurilio to use HOST = /var/run/postgresql:27541 worked. Can this (That local socket specification won't work by specifying the unix socket pathname) possibly be specified in the documentation?

Warm Regards
Lee

(Also, thanks @DanieleAurilio and @lunny for taking the time to respond)

@lelanthran commented on GitHub (Aug 17, 2023): Hello all, @DanieleAurilio, @lunny The suggestion from @DanieleAurilio to use `HOST = /var/run/postgresql:27541` worked. Can this (That local socket specification won't work by specifying the unix socket pathname) possibly be specified in the documentation? Warm Regards Lee (Also, thanks @DanieleAurilio and @lunny for taking the time to respond)
Author
Owner

@Luisgustavom1 commented on GitHub (Oct 3, 2023):

Hello
I was very interested in solving this issue. But before implementing it I wanted to confirm what the correct behavior should be:

  1. Should the behavior be the same as in the doc? I think this is the right behavior. Because this way we avoid confusion like this, as well as allowing the user greater freedom and versatility in constructing HOST paths.

What do you maintainers think about this?

@Luisgustavom1 commented on GitHub (Oct 3, 2023): Hello I was very interested in solving this issue. But before implementing it I wanted to confirm what the correct behavior should be: 1. Should the behavior be the same as in the doc? I think this is the right behavior. Because this way we avoid confusion like this, as well as allowing the user greater freedom and versatility in constructing HOST paths. What do you maintainers think about this?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#10792