Skip to content

Cannot adopt more than 65535 repositories with PostgreSQL #19137

@Mcdostone

Description

@Mcdostone

Gitea Version

1.16.4

Git Version

2.25.1

Operating System

Linux

How are you running Gitea?

Nothing fancy

curl -L "https://github.com/go-gitea/gitea/releases/download/v1.16.4/gitea-1.16.4-linux-amd64" --output /tmp/gitea
/tmp/gitea

Database

PostgreSQL

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

Mar 18 21:54:55 linux- gitea[584975]: 2022/03/18 21:54:55 ...pi/v1/admin/adopt.go:51:ListUnadoptedRepositories() [E] InternalServerError: Count: pq: got 236972 parameters but PostgreSQL only supports 65535 parameters
Mar 18 21:54:55 linux gitea[584975]: 2022/03/18 21:54:55 router: completed GET /api/v1/admin/unadopted?page=1&limit=1000&pattern=&access_token=7feec787664a21a74aec942a71343b46d2d52360&sudo=&token= for 129.6.76.113:0, 500 Internal Server Error in 3618.9ms @ admin/adopt.go:20(admin.ListUnadoptedRepositories)

Description

The bug

I have more than 65535 unadopted repositories in gitea-repositories.
When I want to list them, I have a 500 HTTP status:

curl -X 'GET' 'http://localhost:3000/api/v1/admin/unadopted?page=1&limit=1000' -H 'authorization: Basic XXXXX'`

The Cause

After some voodoo debugging, I figured out the error happens in /services/repository/adopt.go:249, after the function call at services/repository/adopt.go:347

// Caller is services/repository/adopt.go:L347
// services/repository/adopt.go:249
       repos, _, err := models.GetUserRepositories(&models.SearchRepoOptions{
		Actor:   ctxUser,
		Private: true,
		ListOptions: db.ListOptions{
			Page:     1,
			PageSize: len(repoNamesToCheck),     // len(repoNamesToCheck) is greater than 65535
		}, LowerNames: repoNamesToCheck,             // 💀 the array contains more than 65535 items 
	})
	if err != nil {
		return err                                   // 🔥 Count: pq: got 236972 parameters but PostgreSQL only supports 65535 parameters"
	}
	```

Activity

added a commit that references this issue on Mar 19, 2022
c1115f6
added a commit that references this issue on Mar 21, 2022
b05b401
added a commit that references this issue on Mar 21, 2022
534551e
added a commit that references this issue on Mar 22, 2022
23b8214
added this to the 1.16.5 milestone on Mar 23, 2022
added a commit that references this issue on Mar 28, 2022
dd05549
locked and limited conversation to collaborators on Apr 28, 2022
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

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Participants

      @lunny@zeripath@Mcdostone

      Issue actions

        Cannot adopt more than 65535 repositories with PostgreSQL · Issue #19137 · go-gitea/gitea