Request to /pulls causes runtime error: invalid memory address or nil pointer dereference #8990

Closed
opened 2025-11-02 08:24:59 -06:00 by GiteaMirror · 4 comments
Owner

Originally created by @max-m on GitHub (May 23, 2022).

Description

This is the same error as reported in #17163, but the bot has locked it by now.

2022/05/23 14:48:28 routers/web/base.go:130:1() [E] PANIC: runtime error: invalid memory address or nil pointer dereference
	/usr/local/go/src/runtime/panic.go:220 (0x457635)
	/usr/local/go/src/runtime/signal_unix.go:818 (0x457605)
	/go/src/code.gitea.io/gitea/models/pull.go:350 (0x1abeea6)
	/go/src/code.gitea.io/gitea/services/pull/pull.go:781 (0x1abee82)
	/go/src/code.gitea.io/gitea/services/pull/pull.go:755 (0x1abebbd)
	/go/src/code.gitea.io/gitea/routers/web/user/home.go:569 (0x1fd5da4)
	/go/src/code.gitea.io/gitea/routers/web/user/home.go:333 (0x1fd5126)
	/go/src/code.gitea.io/gitea/modules/web/route.go:74 (0x1e493e4)
	/usr/local/go/src/net/http/server.go:2084 (0x7ac7ae)
	/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:442 (0x1657d15)
	/usr/local/go/src/net/http/server.go:2084 (0x7ac7ae)
	/go/src/code.gitea.io/gitea/modules/web/route.go:113 (0x1e49bd1)
	/usr/local/go/src/net/http/server.go:2084 (0x7ac7ae)
	/go/src/code.gitea.io/gitea/modules/web/route.go:113 (0x1e49bd1)
	/usr/local/go/src/net/http/server.go:2084 (0x7ac7ae)
	/go/src/code.gitea.io/gitea/modules/web/route.go:113 (0x1e49bd1)
	/usr/local/go/src/net/http/server.go:2084 (0x7ac7ae)
	/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/middleware/get_head.go:37 (0x1e79484)
	/usr/local/go/src/net/http/server.go:2084 (0x7ac7ae)
	/go/src/code.gitea.io/gitea/modules/web/route.go:113 (0x1e49bd1)
	/usr/local/go/src/net/http/server.go:2084 (0x7ac7ae)
	/go/src/code.gitea.io/gitea/modules/context/context.go:757 (0x1669894)
	/usr/local/go/src/net/http/server.go:2084 (0x7ac7ae)
	/go/pkg/mod/github.com/!n!y!times/gziphandler@v1.1.1/gzip.go:338 (0x2031ec1)
	/usr/local/go/src/net/http/server.go:2084 (0x7ac7ae)
	/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:71 (0x1655b4c)
	/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:314 (0x16574fb)
	/usr/local/go/src/net/http/server.go:2084 (0x7ac7ae)
	/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:442 (0x1657d15)
	/usr/local/go/src/net/http/server.go:2084 (0x7ac7ae)
	/go/src/code.gitea.io/gitea/routers/web/base.go:169 (0x2034891)
	/usr/local/go/src/net/http/server.go:2084 (0x7ac7ae)
	/go/pkg/mod/gitea.com/go-chi/session@v0.0.0-20211218221615-e3605d8b28b8/session.go:257 (0x14622bd)
	/usr/local/go/src/net/http/server.go:2084 (0x7ac7ae)
	/go/src/code.gitea.io/gitea/modules/public/public.go:42 (0x159591b)
	/usr/local/go/src/net/http/server.go:2084 (0x7ac7ae)
	/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:71 (0x1655b4c)
	/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:314 (0x16574fb)
	/usr/local/go/src/net/http/server.go:2084 (0x7ac7ae)
	/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:442 (0x1657d15)
	/usr/local/go/src/net/http/server.go:2084 (0x7ac7ae)
	/go/src/code.gitea.io/gitea/routers/common/middleware.go:78 (0x1e7f661)
	/usr/local/go/src/net/http/server.go:2084 (0x7ac7ae)
	/go/src/code.gitea.io/gitea/routers/common/logger.go:23 (0x1e7e8ef)
	/usr/local/go/src/net/http/server.go:2084 (0x7ac7ae)
	/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/middleware/strip.go:30 (0x1e7c1f8)
	/usr/local/go/src/net/http/server.go:2084 (0x7ac7ae)
	/go/pkg/mod/github.com/chi-middleware/proxy@v1.1.1/middleware.go:37 (0x1e78af6)
	/usr/local/go/src/net/http/server.go:2084 (0x7ac7ae)
	/go/src/code.gitea.io/gitea/routers/common/middleware.go:31 (0x1e7f4b9)
	/usr/local/go/src/net/http/server.go:2084 (0x7ac7ae)
	/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:88 (0x1655b01)
	/go/src/code.gitea.io/gitea/modules/web/route.go:328 (0x1e4ca2d)
	/usr/local/go/src/net/http/server.go:2916 (0x7afd9a)
	/usr/local/go/src/net/http/server.go:1966 (0x7ab256)
	/usr/local/go/src/runtime/asm_amd64.s:1571 (0x474600)

The crash occurs in the same function it did in the previous bug report.

The repository in question has one pull request listed in the pull_repo database table, but not in the pull_request table.
This PR was created in 2015 and the Gitea instance has been updated multiple times since then.
Both repositories, the source and the destination, are still available on disk. The source repository has since been archived and moved into another account.

I’ve tried to replicate the issue by forking a different repository, creating a PR for it, then archiving the forked repo and transferring it to another account. This PR is listed in the pull_request table and the pull request UI for it can be opened.

Gitea Version

1.16.8

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

2.30.3

Operating System

Debian Bullseye

How are you running Gitea?

Official Docker container (gitea/gitea:1.16.8).

Database

MySQL

Originally created by @max-m on GitHub (May 23, 2022). ### Description This is the same error as reported in #17163, but the bot has locked it by now. ``` 2022/05/23 14:48:28 routers/web/base.go:130:1() [E] PANIC: runtime error: invalid memory address or nil pointer dereference /usr/local/go/src/runtime/panic.go:220 (0x457635) /usr/local/go/src/runtime/signal_unix.go:818 (0x457605) /go/src/code.gitea.io/gitea/models/pull.go:350 (0x1abeea6) /go/src/code.gitea.io/gitea/services/pull/pull.go:781 (0x1abee82) /go/src/code.gitea.io/gitea/services/pull/pull.go:755 (0x1abebbd) /go/src/code.gitea.io/gitea/routers/web/user/home.go:569 (0x1fd5da4) /go/src/code.gitea.io/gitea/routers/web/user/home.go:333 (0x1fd5126) /go/src/code.gitea.io/gitea/modules/web/route.go:74 (0x1e493e4) /usr/local/go/src/net/http/server.go:2084 (0x7ac7ae) /go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:442 (0x1657d15) /usr/local/go/src/net/http/server.go:2084 (0x7ac7ae) /go/src/code.gitea.io/gitea/modules/web/route.go:113 (0x1e49bd1) /usr/local/go/src/net/http/server.go:2084 (0x7ac7ae) /go/src/code.gitea.io/gitea/modules/web/route.go:113 (0x1e49bd1) /usr/local/go/src/net/http/server.go:2084 (0x7ac7ae) /go/src/code.gitea.io/gitea/modules/web/route.go:113 (0x1e49bd1) /usr/local/go/src/net/http/server.go:2084 (0x7ac7ae) /go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/middleware/get_head.go:37 (0x1e79484) /usr/local/go/src/net/http/server.go:2084 (0x7ac7ae) /go/src/code.gitea.io/gitea/modules/web/route.go:113 (0x1e49bd1) /usr/local/go/src/net/http/server.go:2084 (0x7ac7ae) /go/src/code.gitea.io/gitea/modules/context/context.go:757 (0x1669894) /usr/local/go/src/net/http/server.go:2084 (0x7ac7ae) /go/pkg/mod/github.com/!n!y!times/gziphandler@v1.1.1/gzip.go:338 (0x2031ec1) /usr/local/go/src/net/http/server.go:2084 (0x7ac7ae) /go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:71 (0x1655b4c) /go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:314 (0x16574fb) /usr/local/go/src/net/http/server.go:2084 (0x7ac7ae) /go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:442 (0x1657d15) /usr/local/go/src/net/http/server.go:2084 (0x7ac7ae) /go/src/code.gitea.io/gitea/routers/web/base.go:169 (0x2034891) /usr/local/go/src/net/http/server.go:2084 (0x7ac7ae) /go/pkg/mod/gitea.com/go-chi/session@v0.0.0-20211218221615-e3605d8b28b8/session.go:257 (0x14622bd) /usr/local/go/src/net/http/server.go:2084 (0x7ac7ae) /go/src/code.gitea.io/gitea/modules/public/public.go:42 (0x159591b) /usr/local/go/src/net/http/server.go:2084 (0x7ac7ae) /go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:71 (0x1655b4c) /go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:314 (0x16574fb) /usr/local/go/src/net/http/server.go:2084 (0x7ac7ae) /go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:442 (0x1657d15) /usr/local/go/src/net/http/server.go:2084 (0x7ac7ae) /go/src/code.gitea.io/gitea/routers/common/middleware.go:78 (0x1e7f661) /usr/local/go/src/net/http/server.go:2084 (0x7ac7ae) /go/src/code.gitea.io/gitea/routers/common/logger.go:23 (0x1e7e8ef) /usr/local/go/src/net/http/server.go:2084 (0x7ac7ae) /go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/middleware/strip.go:30 (0x1e7c1f8) /usr/local/go/src/net/http/server.go:2084 (0x7ac7ae) /go/pkg/mod/github.com/chi-middleware/proxy@v1.1.1/middleware.go:37 (0x1e78af6) /usr/local/go/src/net/http/server.go:2084 (0x7ac7ae) /go/src/code.gitea.io/gitea/routers/common/middleware.go:31 (0x1e7f4b9) /usr/local/go/src/net/http/server.go:2084 (0x7ac7ae) /go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:88 (0x1655b01) /go/src/code.gitea.io/gitea/modules/web/route.go:328 (0x1e4ca2d) /usr/local/go/src/net/http/server.go:2916 (0x7afd9a) /usr/local/go/src/net/http/server.go:1966 (0x7ab256) /usr/local/go/src/runtime/asm_amd64.s:1571 (0x474600) ``` The crash occurs in the same function it did in the previous bug report. The repository in question has one pull request listed in the `pull_repo` database table, but not in the `pull_request` table. This PR was created in 2015 and the Gitea instance has been updated multiple times since then. Both repositories, the source and the destination, are still available on disk. The source repository has since been archived and moved into another account. I’ve tried to replicate the issue by forking a different repository, creating a PR for it, then archiving the forked repo and transferring it to another account. This PR is listed in the `pull_request` table and the pull request UI for it can be opened. ### Gitea Version 1.16.8 ### Can you reproduce the bug on the Gitea demo site? No ### Log Gist _No response_ ### Screenshots _No response_ ### Git Version 2.30.3 ### Operating System Debian Bullseye ### How are you running Gitea? Official Docker container (`gitea/gitea:1.16.8`). ### Database MySQL
GiteaMirror added the type/bugissue/workaround labels 2025-11-02 08:24:59 -06:00
Author
Owner

@zeripath commented on GitHub (May 24, 2022):

This has the same root as the referenced issue.

https://github.com/go-gitea/gitea/issues/17163#issuecomment-929486481

That would imply that issue.PullRequest() is returning a nil PullRequest.

Meaning that there is an issue in the issues that doesn't get its pull request loaded:

7ce938b6c7/services/pull/pull.go (L690)

https://github.com/go-gitea/gitea/issues/17163#issuecomment-929489328

Suggesting ... that there is an issue that is marked as a pull request but has either:

  • no PR associated with it
  • or a PRID == 0?

You will have an issue that has a missing pullrequest.

@zeripath commented on GitHub (May 24, 2022): This has the same root as the referenced issue. https://github.com/go-gitea/gitea/issues/17163#issuecomment-929486481 > That would imply that issue.PullRequest() is returning a nil PullRequest. > > Meaning that there is an issue in the `issues` that doesn't get its pull request loaded: > https://github.com/go-gitea/gitea/blob/7ce938b6c7a7c66eb615cf391e9742a65e3e3f95/services/pull/pull.go#L690 https://github.com/go-gitea/gitea/issues/17163#issuecomment-929489328 > Suggesting ... that there is an issue that is marked as a pull request but has either: > > * no PR associated with it > * or a PRID == 0? You will have an issue that has a missing pullrequest.
Author
Owner

@max-m commented on GitHub (May 25, 2022):

Yes, that’s pretty much what I noticed:

The repository in question has one pull request listed in the pull_repo database table, but not in the pull_request table.

You are also right that there’s an entry in the issues table for that repository with the is_pull flag set.
I assume the pull_repo table is very old (GitHub’s search didn’t turn up anything in any Go codebase) and might have been missed by one of the many migrations my instance has seen since its original installation as Gogs.

I was able to partially restore the PR by manually creating an entry in the pull_request table by looking at what little information is stored in the pull_repo table:

id pull_id from_repo_id from_branch to_repo_id to_branch can_auto_merge is_merged is_closed before_commit after_commit created updated
1 1 7 master 6 master 1 0 0 2015-09-07 20:58:10 2015-09-07 20:58:10

=>

pull_id pull_index head_barcnh issue_id index head_branch type status head_repo_id base_repo_id base_branch merge_base has_merged merged_commit_id merged merger_id merged_unix conflicted_files commits_ahead commits_behind changed_protected_files flow
1 NULL NULL 1 1 master 0 0 7 6 master 83d9b42b358cd7d2706e1c07e1fc933fa2e3a3dc 0 NULL 0 NULL [] 1 0 null 0

Now the PR doesn’t cause a crash, but This pull request is broken due to missing fork information. and the following message appears in the log:

getLastCommitStatus: cant get last commit of pull [2]: object does not exist [id: refs/pull/1/head, rel_path: ]

And indeed, the repository lacks this file. However the repository root contains a pulls directory containing a 1.patch file.
So in theory no data has been lost but the database and on-disk formats have changed at some point and a migration was likely missed or failed. I suppose that, if this was an important repository and PR, I could restore it fully.

Still I think it would be nice to have a check in place that prevents the invalid memory access from happening if the database has become inconsistent.

@max-m commented on GitHub (May 25, 2022): Yes, that’s pretty much what I noticed: > The repository in question has one pull request listed in the `pull_repo` database table, but not in the `pull_request` table. You are also right that there’s an entry in the `issues` table for that repository with the `is_pull` flag set. I assume the `pull_repo` table is *very old* (GitHub’s search didn’t turn up anything in any Go codebase) and might have been missed by one of the many migrations my instance has seen since its original installation as Gogs. I was able to partially restore the PR by manually creating an entry in the `pull_request` table by looking at what little information is stored in the `pull_repo` table: | id | pull_id | from_repo_id | from_branch | to_repo_id | to_branch | can_auto_merge | is_merged | is_closed | before_commit | after_commit | created | updated | | -- | ------- | ------------ | ----------- | ---------- | --------- | -------------- | --------- | --------- | ------------- | ------------ | ------- | ------------------- | | 1 | 1 | 7 | master | 6 | master | 1 | 0 | 0 | | | 2015-09-07 20:58:10 | 2015-09-07 20:58:10 | => | pull_id | pull_index | head_barcnh | issue_id | index | head_branch | type | status | head_repo_id | base_repo_id | base_branch | merge_base | has_merged | merged_commit_id | merged | merger_id | merged_unix | conflicted_files | commits_ahead | commits_behind | changed_protected_files | flow | | ------- | ---------- | ----------- | -------- | ----- | ----------- | ---- | ------ | ------------ | ------------ | ----------- | ---------------------------------------- | ---------- | ---------------- | ------ | --------- | ----------- | ---------------- | ------------- | -------------- | ----------------------- | ---- | | 1 | NULL | NULL | 1 | 1 | master | 0 | 0 | 7 | 6 | master | 83d9b42b358cd7d2706e1c07e1fc933fa2e3a3dc | 0 | | NULL | 0 | NULL | [] | 1 | 0 | null | 0 | Now the PR doesn’t cause a crash, but `This pull request is broken due to missing fork information. ` and the following message appears in the log: ``` getLastCommitStatus: cant get last commit of pull [2]: object does not exist [id: refs/pull/1/head, rel_path: ] ``` And indeed, the repository lacks this file. However the repository root contains a `pulls` directory containing a `1.patch` file. So in theory no data has been lost but the database and on-disk formats have changed at some point and a migration was likely missed or failed. I suppose that, if this was an important repository and PR, I could restore it fully. Still I think it would be nice to have a check in place that prevents the invalid memory access from happening if the database has become inconsistent.
Author
Owner

@singuliere commented on GitHub (May 28, 2022):

@max-m see this forum topic for additional information about the pull_repo table and comments regarding gitea doctor.

@singuliere commented on GitHub (May 28, 2022): @max-m see [this forum topic](https://forum.hostea.org/t/gitea-upgrade-from-gogs-to-1-16-8-unmigrated-pull-repo-table/73) for additional information about the `pull_repo` table and comments regarding `gitea doctor`.
Author
Owner

@lunny commented on GitHub (Apr 29, 2023):

I think it's a Gogs problem from 1abfe4e05f which is referenced from https://forum.hostea.org/t/gitea-upgrade-from-gogs-to-1-16-8-unmigrated-pull-repo-table/73 which migration is absent. So I think if you encounter this problem, you have to fix it manually. It's difficult to fix it from Gitea's side.

I will close this as some workaround has been mentioned via gitea doctor.

@lunny commented on GitHub (Apr 29, 2023): I think it's a Gogs problem from https://github.com/go-gitea/gitea/commit/1abfe4e05f2c936ab43c8188003a33213b245a56 which is referenced from https://forum.hostea.org/t/gitea-upgrade-from-gogs-to-1-16-8-unmigrated-pull-repo-table/73 which migration is absent. So I think if you encounter this problem, you have to fix it manually. It's difficult to fix it from Gitea's side. I will close this as some workaround has been mentioned via `gitea doctor`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#8990