gogs: Broken pull requests merge action after cherry picking

Gogs version

0.12.3 and 0.12.7

Git version

  • Server: 2.36.1
  • Client: -

Operating system

FreeBSD 12.2-stable

Database

PostgreSQL 11.16

Describe the bug

Clicking on the “Merge” button on a PR crashes gogs, needing a full restart of the service to get it up again.

To reproduce

I’ve a repo with this structure:

  • master
    • dev
      • feature/implement-whatever
      • fix/incorrect-handling-whatever
      • etc
    • release/1.0.0
    • release/1.1.0
    • release/1.1.1
    • etc

The workflow is, working on dev until we get to a point where we can make a release, create a branch release/1.1.1 (for example) and then merge that into master (using gogs, through a PR). Release branches are kept in the repo, but the feature/fix/etc branches are deleted after merged into dev.

So far so good, worked pretty well.

Now, with dev running 1.2.0 we needed to “backport” some fixes made in the dev branch, into a branch release/1.1.2 (bugfix for 1.1.x) without pulling all the work done in dev for the next release.

We created release/1.1.2 (from release/1.1.1) and then used cherry-pick to backport those fixes from dev. We did double check the branch locally, no conflicts, all ok and we pushed it to the main repo.

After that, we kept working normally and on the next merge of a fix/feature branch into dev, through gogs PR interface, gogs blows up and stops working (restart is needed).

In the log files we can see this message:

[Macaron] PANIC: Value not found for type *repo.HTTPContext
/wrkdirs/usr/ports/devel/gogs/work/gogs-0.12.3/vendor/gopkg.in/macaron.v1/context.go:123 (0x1b62934)
/wrkdirs/usr/ports/devel/gogs/work/gogs-0.12.3/vendor/gopkg.in/macaron.v1/context.go:112 (0x1b75a65)
/wrkdirs/usr/ports/devel/gogs/work/gogs-0.12.3/vendor/gopkg.in/macaron.v1/recovery.go:161 (0x1b75a58)
/wrkdirs/usr/ports/devel/gogs/work/gogs-0.12.3/vendor/gopkg.in/macaron.v1/logger.go:40 (0x1b66377)
/wrkdirs/usr/ports/devel/gogs/work/gogs-0.12.3/vendor/github.com/go-macaron/inject/inject.go:157 (0x1b2fa54)
/wrkdirs/usr/ports/devel/gogs/work/gogs-0.12.3/vendor/github.com/go-macaron/inject/inject.go:135 (0x1b2f7f9)
/wrkdirs/usr/ports/devel/gogs/work/gogs-0.12.3/vendor/gopkg.in/macaron.v1/context.go:121 (0x1b627bc)
/wrkdirs/usr/ports/devel/gogs/work/gogs-0.12.3/vendor/gopkg.in/macaron.v1/router.go:187 (0x1b76cb0)
/wrkdirs/usr/ports/devel/gogs/work/gogs-0.12.3/vendor/gopkg.in/macaron.v1/router.go:303 (0x1b6ede5)
/wrkdirs/usr/ports/devel/gogs/work/gogs-0.12.3/vendor/gopkg.in/macaron.v1/macaron.go:220 (0x1b676ed)
/usr/local/go/src/net/http/server.go:2843 (0x1aca622)
/usr/local/go/src/net/http/server.go:1925 (0x1ac5e2c)
/usr/local/go/src/runtime/asm_amd64.s:1374 (0x1774060)

(that’s the first appearance of the error in our log files)

We did upgrade to 0.12.7, gogs still crashes, this is the output in the logs:

[Macaron] PANIC: Value not found for type *repo.HTTPContext
gopkg.in/macaron.v1@v1.3.9/context.go:123 (0x1a016bd)
gopkg.in/macaron.v1@v1.3.9/context.go:112 (0x1a07346)
gopkg.in/macaron.v1@v1.3.9/recovery.go:161 (0x1a0733d)
gopkg.in/macaron.v1@v1.3.9/logger.go:40 (0x1a048e4)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:157 (0x19d8714)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:135 (0x19d863c)
gopkg.in/macaron.v1@v1.3.9/context.go:121 (0x1a015d2)
gopkg.in/macaron.v1@v1.3.9/router.go:187 (0x1a0d1c4)
gopkg.in/macaron.v1@v1.3.9/router.go:303 (0x1a0e32c)
gopkg.in/macaron.v1@v1.3.9/macaron.go:220 (0x1a06464)
net/http/server.go:2916 (0x198141a)
net/http/server.go:1966 (0x197c8d6)
runtime/asm_amd64.s:1571 (0x1671f80)

Expected behavior

I’d expect to get PRs merged when I click on the “Merge” button in a PR page

Additional context

No response

Code of Conduct

  • I agree to follow this project’s Code of Conduct

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

Built gogs from sources (main branch) and tried again, this time the PR merge did not crash.

Thanks a lot @unknwon for fixing this.

Ok, built gogs from sources (branch jc/http-panic), go 1.18.2, git 2.36.1, then started it instead of our previous version.

Then I created a new branch in our repo, from dev, called test/new-gogs-fix, and modified a README file. I pushed those changes to the new branch, then in gogs I created a new PR to merge test/new-gogs-fix into dev, all good. Then I clicked merge and got a 502 gateway timeout, gogs crashed.

This is what I see in the logs now:

2022/06/03 18:01:36 [TRACE] Session ID: 3bbd1715c9dc3f3d
2022/06/03 18:01:36 [TRACE] CSRF Token: TXcV2RAeLpoG3aRJa1895ub-7DI6MTY1NDI3MTkxODQ3Mjg0NDM1Mw
2022/06/03 18:01:36 [TRACE] NewMessageFrom (htmlBody):
<!DOCTYPE html>
<html>
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>[repo] test gogs fix for our PR merge crashes (#881)</title>
</head>

<body>
        <p><p>This pr is merged on a new version of gogs, as a POC</p>
</p>
        <p>
                ---
                <br>
                <a href="https://whatever.com/path/to/repo/pulls/881">View it on Gogs</a>.
        </p>
</body>
</html>
2022/06/03 18:01:38 [TRACE] Pull request merged: 445
2022/06/03 18:01:38 [TRACE] DeliverHooks [repo_id: 1]
2022/06/03 18:01:38 [TRACE] AddTestPullRequestTask [head_repo_id: 1, head_branch: dev]: finding pull requests
2022/06/03 18:01:38 [TRACE] addHeadRepoTasks[439]: composing new test task
2022/06/03 18:01:38 [TRACE] PullRequest[439].UpdatePatch: ignored corrupted data
2022/06/03 18:01:38 [TRACE] PushToBaseRepo[1]: pushing commits to base repo 'refs/pull/873/head'
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x296b402]

goroutine 865 [running]:
gogs.io/gogs/internal/db.(*Repository).mustOwner(0x1780208?, {0x17897f0?, 0xc0000a2000?})
        /home/wu/repos/gogs/internal/db/repo.go:411 +0x22
gogs.io/gogs/internal/db.(*Repository).repoPath(0x0, {0x17897f0?, 0xc0000a2000?})
        /home/wu/repos/gogs/internal/db/repo.go:536 +0x28
gogs.io/gogs/internal/db.(*Repository).RepoPath(...)
        /home/wu/repos/gogs/internal/db/repo.go:540
gogs.io/gogs/internal/db.(*PullRequest).PushToBaseRepo(0xc0028d8460)
        /home/wu/repos/gogs/internal/db/pull.go:674 +0xfa
gogs.io/gogs/internal/db.addHeadRepoTasks({0xc00226db90, 0x1, 0x3?})
        /home/wu/repos/gogs/internal/db/pull.go:766 +0x125
gogs.io/gogs/internal/db.AddTestPullRequestTask(0xc001d8a200, 0x0?, {0xc002ecd250, 0x3}, 0x0)
        /home/wu/repos/gogs/internal/db/pull.go:811 +0x290
created by gogs.io/gogs/internal/db.(*PullRequest).Merge.func1
        /home/wu/repos/gogs/internal/db/pull.go:200 +0x14b

Hope it helps 😅