go-gitea / gitea

Git with a cup of tea! Painless self-hosted all-in-one software development service, including Git hosting, code review, team collaboration, package registry and CI/CD
https://gitea.com
MIT License
44.21k stars 5.42k forks source link

Internal Server Error 500 when browsing the front page of a particular repository #2033

Closed typeless closed 7 years ago

typeless commented 7 years ago

The following is the git command that causes the error

git log --pretty=format:%H --name-only -1 128ef2198170e51ab90601592f2ddc3be15ee170^ -- .gitignore

Note that the commit in question is the initial commit of the repository.

typeless commented 7 years ago

Removing the trailing '^' seems to fix the problem. I haven't figured out the root cause though.

ethantkoenig commented 7 years ago

@typeless I believe this will be fixed by https://github.com/go-gitea/git/pull/66. Can you pull the latest changes from code.gitea.io/git, and see if that fixes the problem?

typeless commented 7 years ago

@ethantkoenig You are correct. The problem is fixed. 👍

typeless commented 7 years ago

Sorry but this problem is probably not fixed yet.

Currently I made a workaround which might be the correct fix or not:

diff --git a/vendor/code.gitea.io/git/tree_entry.go b/vendor/code.gitea.io/git/tree_entry.go
index 7ea4d21..110f93c 100644
--- a/vendor/code.gitea.io/git/tree_entry.go
+++ b/vendor/code.gitea.io/git/tree_entry.go
@@ -278,13 +278,19 @@ func getNextCommitInfos(state *getCommitInfoState) error {

 func logCommand(exclusiveStartHash string, state *getCommitInfoState) *Command {
        var commitHash string
+
+       numRemainingEntries := len(state.entries) - len(state.commits)
+
        if len(exclusiveStartHash) == 0 {
                commitHash = state.headCommit.ID.String()
        } else {
-               commitHash = exclusiveStartHash + "^"
+               commitHash = exclusiveStartHash
+               if numRemainingEntries > 1 {
+                       commitHash += "^"
+               }
        }
+
        var command *Command
-       numRemainingEntries := len(state.entries) - len(state.commits)
        if numRemainingEntries < 32 {
                searchSize := (numRemainingEntries + 1) / 2
                command = NewCommand("log", prettyLogFormat, "--name-only",
lunny commented 7 years ago

@typeless could you send a PR?

typeless commented 7 years ago

@lunny No problem.

ethantkoenig commented 7 years ago

@typeless Omitting the caret does not fix the root of the problem (and introduces a potential infinite loop). Could you share the repo where the error still occurs, so that we can diagnose what the underlying cause is?

typeless commented 7 years ago

@ethantkoenig I am afraid it's not possible because the repo is very large. The only thing I found suspicious is the file which causes the problem is a .gitignore which happens to have only one commit history. And based on the log I collected, the actual git command which led to the error can make the same error if I try to enter the command via CLI. A file with only one commit is actually not possible to get its parent commit using the caret.

ethantkoenig commented 7 years ago

@typeless Could you checkout https://github.com/ethantkoenig/gitea/tree/debug_get_commits_info (latest gitea master plus some print statements for debugging), try to view the problematic repo, and show me what gets printed?

typeless commented 7 years ago

@ethantkoenig I have to cut the rest the filenames listing otherwise it would exceed the maximum limit of the comment. Those are not interesting though, just list of the paths/filenames. (Actually, the files are too many. The server was hanging so I had to stop it manually.)

Jun 26 11:04:40 DIR-101 gitea[1039]: logCommand:
Jun 26 11:04:40 DIR-101 gitea[1039]:   state=&{entries:map[abi:0xc421f2bc80 developers:0xc421f2bf80 system:0xc421ffa5a0 build:0xc421f2be60 development:0xc421ffa000 bootable:0xc421f2bda0 device:0xc421ffa060 hardware:0xc421ffa1e0 platform_testing:0xc421ffa480 sdk:0xc421ffa540 CastDrivers:0xc421f2bb60 cts:0xc421f2bec0 external:0xc421ffa120 libcore:0xc421ffa2a0 build.sh:0xc421f2be00 dalvik:0xc421f2bf20 docs:0xc421ffa0c0 kernel:0xc421ffa240 README.md:0xc421f2bc20 libnativehelper:0xc421ffa300 frameworks:0xc421ffa180 ndk:0xc421ffa360 prebuilts:0xc421ffa4e0 vendor:0xc421ffa600 Makefile:0xc421f2bbc0 art:0xc421f2bce0 bionic:0xc421f2bd40 packages:0xc421ffa3c0 pdk:0xc421ffa420] commits:map[] lastCommitHash: lastCommit:<nil> treePath: headCommit:0xc42127d8c0 nextSearchSize:16}
Jun 26 11:04:40 DIR-101 gitea[1039]:   command=git log --pretty=format:%H --name-only -15 3fbef28b2275349d1f249a9300ef390c469c8d32 -- libnativehelper frameworks ndk art bionic packages pdk prebuilts vendor Makefile abi developers system build development bootable device hardware platform_testing CastDrivers cts external libcore sdk dalvik docs kernel README.md build.sh
Jun 26 11:04:41 DIR-101 gitea[1039]: getNextCommitInfos:
Jun 26 11:04:41 DIR-101 gitea[1039]:   stdout=
Jun 26 11:04:41 DIR-101 gitea[1039]: [[3fbef28b2275349d1f249a9300ef390c469c8d32
Jun 26 11:04:41 DIR-101 gitea[1039]: external/sepolicy/domain.te
Jun 26 11:04:41 DIR-101 gitea[1039]: vendor/castles/cast_binder/AutoRebootFlag
Jun 26 11:04:41 DIR-101 gitea[1039]: vendor/castles/cast_binder/NTP_Flag
Jun 26 11:04:41 DIR-101 gitea[1039]: vendor/castles/cast_binder/ULDPasswordHash
Jun 26 11:04:41 DIR-101 gitea[1039]: vendor/castles/cast_binder/c_library/libcaredirect/CommandLevel.c
Jun 26 11:04:41 DIR-101 gitea[1039]: vendor/castles/cast_binder/cast_binder_list.mk
Jun 26 11:04:41 DIR-101 gitea[1039]: vendor/castles/cast_binder/cpp_server/system/BnSystemService.cpp
Jun 26 11:04:41 DIR-101 gitea[1039]: vendor/castles/cast_binder/cpp_server/system/BnSystemService.h
Jun 26 11:04:41 DIR-101 gitea[1039]: vendor/castles/cast_binder/cpp_server/system/BpSystemService.cpp
Jun 26 11:04:41 DIR-101 gitea[1039]: vendor/castles/cast_binder/cpp_server/system/ISystemService.h
Jun 26 11:04:41 DIR-101 gitea[1039]: vendor/castles/cast_binder/java_client/src/CTOS/CtSystem.java
Jun 26 11:04:41 DIR-101 gitea[1039]: vendor/castles/cast_binder/java_client/src/android/binder/aidl/ISystemAPI.aidl
Jun 26 11:04:41 DIR-101 gitea[1039]: vendor/castles/cast_binder/java_client/src/com/android/test.java
Jun 26 11:04:41 DIR-101 gitea[1039]: vendor/castles/selinux/ctos_binder.te
Jun 26 11:04:41 DIR-101 gitea[1039]: vendor/castles/selinux/system_app.te
Jun 26 11:04:41 DIR-101 gitea[1039]: vendor/castles/system/Launcher/src/com/ctos/CastlesStart/Launcher.java
Jun 26 11:04:41 DIR-101 gitea[1039]: vendor/castles/system/SystemPanel/Android.mk
Jun 26 11:04:41 DIR-101 gitea[1039]: vendor/castles/system/SystemPanel/AndroidManifest.xml
Jun 26 11:04:41 DIR-101 gitea[1039]: vendor/castles/system/SystemPanel/res/drawable-hdpi/ic_launcher.png
ethantkoenig commented 7 years ago

@typeless Sorry, this isn't enough to debug the problem. Is the repo you're using publicly hosted somewhere? It would be helpful if I could run the problematic commands on my own machine.

typeless commented 7 years ago

@ethantkoenig No, it's not public hosted.

I can try to shrink it or git-filter-branch it if that can preserve the problem.

ethantkoenig commented 7 years ago

@typeless Are the repo's contents sensitive?

If the repo's contents are not sensitive, could you upload the repo to try.gitea.io?

If the repo's contents are sensitive, could you share the full log of what I had you run earlier (not here, but maybe in a Github Gist)?

typeless commented 7 years ago

@ethantkoenig The repo belongs to the company I work for. So theoretically any publishment requires to go through certain managerial/bureaucratic process to get the legal permission, which I am reluctant to bother with. 😆

The good news (or bad news?) is that the problem can no longer be reproduced now. It's probably due to the changes happening to the repo. So I will close this for now.