opened
4oo4
username_0
- Gogs version (or commit ref): 0.11.6.0407 
- Go version: 1.6.2
- Git version: 2.7.4
- Operating system:  Ubuntu 16.04
- Database (use `[x]`):
  - [ ] PostgreSQL
  - [X] MySQL
  - [ ] MSSQL
  - [ ] SQLite
- Can you reproduce the bug at https://try.gogs.io:
  - [ ] Yes (provide example URL)
  - [ ] No
  - [X] Not relevant
- Log gist (usually found in `log/gogs.log`):
`gogs.log`:
```
2017/05/02 08:55:23 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 08:55:23 [TRACE] CSRF Token: iv7r-ZSCA1GixKClsdLvhYIPEAM6MTQ5MzczMzMyMzAxNjkxNTI0OQ==
2017/05/02 08:55:23 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 08:55:23 [TRACE] CSRF Token: iv7r-ZSCA1GixKClsdLvhYIPEAM6MTQ5MzczMzMyMzAxNjkxNTI0OQ==
2017/05/02 08:55:23 [TRACE] Template: user/auth/login
2017/05/02 09:05:07 [TRACE] Doing: MirrorUpdate
2017/05/02 09:10:46 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:10:46 [TRACE] CSRF Token: iv7r-ZSCA1GixKClsdLvhYIPEAM6MTQ5MzczMzMyMzAxNjkxNTI0OQ==
2017/05/02 09:10:46 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:10:46 [TRACE] CSRF Token: 112amqPTYuKm_7khs421QC9CIWQ6MTQ5MzczNDI0NjE1MTQ5NDMyMw==
2017/05/02 09:10:46 [TRACE] Template: user/dashboard/dashboard
2017/05/02 09:10:56 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:10:56 [TRACE] CSRF Token: 112amqPTYuKm_7khs421QC9CIWQ6MTQ5MzczNDI0NjE1MTQ5NDMyMw==
2017/05/02 09:11:13 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:11:13 [TRACE] CSRF Token: 112amqPTYuKm_7khs421QC9CIWQ6MTQ5MzczNDI0NjE1MTQ5NDMyMw==
2017/05/02 09:11:13 [TRACE] Template: repo/issue/view
2017/05/02 09:11:24 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:11:24 [TRACE] CSRF Token: 112amqPTYuKm_7khs421QC9CIWQ6MTQ5MzczNDI0NjE1MTQ5NDMyMw==
2017/05/02 09:11:27 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:11:27 [TRACE] CSRF Token: 112amqPTYuKm_7khs421QC9CIWQ6MTQ5MzczNDI0NjE1MTQ5NDMyMw==
2017/05/02 09:11:27 [TRACE] Template: repo/home
2017/05/02 09:11:33 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:11:33 [TRACE] CSRF Token: 112amqPTYuKm_7khs421QC9CIWQ6MTQ5MzczNDI0NjE1MTQ5NDMyMw==
2017/05/02 09:11:33 [TRACE] Template: repo/home
2017/05/02 09:11:51 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:11:51 [TRACE] CSRF Token: 112amqPTYuKm_7khs421QC9CIWQ6MTQ5MzczNDI0NjE1MTQ5NDMyMw==
2017/05/02 09:11:51 [TRACE] Detected encoding: UTF-8 (fast)
2017/05/02 09:11:51 [TRACE] Template: repo/home
2017/05/02 09:15:07 [TRACE] Doing: MirrorUpdate
2017/05/02 09:25:07 [TRACE] Doing: MirrorUpdate
2017/05/02 09:31:13 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:31:13 [TRACE] CSRF Token: 112amqPTYuKm_7khs421QC9CIWQ6MTQ5MzczNDI0NjE1MTQ5NDMyMw==
2017/05/02 09:31:13 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:31:13 [TRACE] CSRF Token: hSPxiUshXWFpuSaZll2wX_b_iXw6MTQ5MzczNTQ3Mzk3MTgwMTQ3MA==
2017/05/02 09:31:14 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:31:14 [TRACE] CSRF Token: hSPxiUshXWFpuSaZll2wX_b_iXw6MTQ5MzczNTQ3Mzk3MTgwMTQ3MA==
2017/05/02 09:31:14 [TRACE] Template: user/auth/login
2017/05/02 09:31:41 [TRACE] Log Mode: File (Trace)
 2017/05/02 09:31:41 [ INFO] Gogs 0.11.6.0407
2017/05/02 09:31:41 [ INFO] Cache Service Enabled
2017/05/02 09:31:41 [ INFO] Session Service Enabled
2017/05/02 09:31:41 [ INFO] Git Version: 2.7.4
2017/05/02 09:31:41 [ INFO] Run Mode: Production
2017/05/02 09:31:41 [TRACE] Doing: CheckRepoStats
2017/05/02 09:31:41 [ INFO] Listen: http://127.0.0.1:3000/gogs
2017/05/02 09:35:29 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:35:29 [TRACE] CSRF Token: hSPxiUshXWFpuSaZll2wX_b_iXw6MTQ5MzczNTQ3Mzk3MTgwMTQ3MA==
2017/05/02 09:35:30 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:35:30 [TRACE] CSRF Token: 0AyVTIXsz9R7r6sMkC-oqRmhCzs6MTQ5MzczNTczMDEwNzE5MDUwOQ==
2017/05/02 09:35:30 [TRACE] Template: user/dashboard/dashboard
2017/05/02 09:35:46 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:35:46 [TRACE] CSRF Token: 0AyVTIXsz9R7r6sMkC-oqRmhCzs6MTQ5MzczNTczMDEwNzE5MDUwOQ==
2017/05/02 09:36:06 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:36:06 [TRACE] CSRF Token: 0AyVTIXsz9R7r6sMkC-oqRmhCzs6MTQ5MzczNTczMDEwNzE5MDUwOQ==
2017/05/02 09:36:06 [TRACE] Template: repo/home
2017/05/02 09:36:11 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:36:11 [TRACE] CSRF Token: 0AyVTIXsz9R7r6sMkC-oqRmhCzs6MTQ5MzczNTczMDEwNzE5MDUwOQ==
2017/05/02 09:36:11 [TRACE] Template: repo/home
2017/05/02 09:36:15 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:36:15 [TRACE] CSRF Token: 0AyVTIXsz9R7r6sMkC-oqRmhCzs6MTQ5MzczNTczMDEwNzE5MDUwOQ==
2017/05/02 09:36:15 [TRACE] Detected encoding: UTF-8 (fast)
2017/05/02 09:36:15 [TRACE] Template: repo/diff/page
2017/05/02 09:36:38 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:36:38 [TRACE] CSRF Token: 0AyVTIXsz9R7r6sMkC-oqRmhCzs6MTQ5MzczNTczMDEwNzE5MDUwOQ==
2017/05/02 09:36:38 [TRACE] Template: repo/commits
2017/05/02 09:36:42 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:36:42 [TRACE] CSRF Token: 0AyVTIXsz9R7r6sMkC-oqRmhCzs6MTQ5MzczNTczMDEwNzE5MDUwOQ==
2017/05/02 09:36:42 [TRACE] Detected encoding: UTF-8 (fast)
2017/05/02 09:36:42 [TRACE] Template: repo/diff/page
2017/05/02 09:36:51 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:36:51 [TRACE] CSRF Token: 0AyVTIXsz9R7r6sMkC-oqRmhCzs6MTQ5MzczNTczMDEwNzE5MDUwOQ==
2017/05/02 09:37:07 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:37:07 [TRACE] CSRF Token: 0AyVTIXsz9R7r6sMkC-oqRmhCzs6MTQ5MzczNTczMDEwNzE5MDUwOQ==
2017/05/02 09:37:07 [TRACE] Template: repo/home
2017/05/02 09:38:42 [TRACE] Log Mode: File (Trace)
2017/05/02 09:38:42 [ INFO] Gogs 0.11.6.0407
2017/05/02 09:38:42 [ INFO] Cache Service Enabled
2017/05/02 09:38:42 [ INFO] Session Service Enabled
2017/05/02 09:38:42 [ INFO] Git Version: 2.7.4
2017/05/02 09:38:42 [ INFO] Run Mode: Production
2017/05/02 09:38:42 [TRACE] Doing: CheckRepoStats
2017/05/02 09:38:42 [ INFO] Listen: http://127.0.0.1:3000/gogs
2017/05/02 09:38:59 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:38:59 [TRACE] CSRF Token: 0AyVTIXsz9R7r6sMkC-oqRmhCzs6MTQ5MzczNTczMDEwNzE5MDUwOQ==
2017/05/02 09:38:59 [TRACE] Template: user/profile
2017/05/02 09:39:02 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:39:02 [TRACE] CSRF Token: 0AyVTIXsz9R7r6sMkC-oqRmhCzs6MTQ5MzczNTczMDEwNzE5MDUwOQ==
2017/05/02 09:39:02 [TRACE] Template: repo/home
2017/05/02 09:39:06 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:39:06 [TRACE] CSRF Token: 0AyVTIXsz9R7r6sMkC-oqRmhCzs6MTQ5MzczNTczMDEwNzE5MDUwOQ==
2017/05/02 09:39:06 [TRACE] Detected encoding: UTF-8 (fast)
2017/05/02 09:39:06 [TRACE] Template: repo/diff/page
2017/05/02 09:39:15 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:39:15 [TRACE] CSRF Token: 0AyVTIXsz9R7r6sMkC-oqRmhCzs6MTQ5MzczNTczMDEwNzE5MDUwOQ==
2017/05/02 09:39:15 [TRACE] Template: user/dashboard/dashboard
2017/05/02 09:44:40 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:44:40 [TRACE] CSRF Token: 0AyVTIXsz9R7r6sMkC-oqRmhCzs6MTQ5MzczNTczMDEwNzE5MDUwOQ==
2017/05/02 09:44:40 [TRACE] Template: user/profile
2017/05/02 09:44:42 [TRACE] Session ID: b1933d701a87aaec
2017/05/02 09:44:42 [TRACE] CSRF Token: 0AyVTIXsz9R7r6sMkC-oqRmhCzs6MTQ5MzczNTczMDEwNzE5MDUwOQ==
2017/05/02 09:44:42 [TRACE] Template: user/dashboard/dashboard
2017/05/02 09:48:42 [TRACE] Doing: MirrorUpdate
```


`xorm.log`:
```
2017/05/02 09:31:41 [xorm] [warn]  2017/05/02 09:31:41.162624 Table repository Column enable_wiki db default is 1, struct default is true
2017/05/02 09:31:41 [xorm] [warn]  2017/05/02 09:31:41.162643 Table repository Column enable_issues db default is 1, struct default is true
2017/05/02 09:31:41 [xorm] [warn]  2017/05/02 09:31:41.162655 Table repository Column enable_pulls db default is 1, struct default is true
2017/05/02 09:31:41 [xorm] [warn]  2017/05/02 09:31:41.162660 Table repository Column is_fork db default is 0, struct default is false
2017/05/02 09:31:41 [xorm] [warn]  2017/05/02 09:31:41.162806 Table action Column is_private db default is 0, struct default is false
2017/05/02 09:31:41 [xorm] [warn]  2017/05/02 09:31:41.163064 Table mirror Column enable_prune db default is 1, struct default is true
2017/05/02 09:31:41 [xorm] [warn]  2017/05/02 09:31:41.163110 Table release Column is_draft db default is 0, struct default is false
2017/05/02 09:31:41 [xorm] [warn]  2017/05/02 09:31:41.163135 Table login_source Column is_actived db default is 0, struct default is false
2017/05/02 09:38:42 [xorm] [warn]  2017/05/02 09:38:42.387559 Table repository Column enable_wiki db default is 1, struct default is true
2017/05/02 09:38:42 [xorm] [warn]  2017/05/02 09:38:42.387580 Table repository Column enable_issues db default is 1, struct default is true
2017/05/02 09:38:42 [xorm] [warn]  2017/05/02 09:38:42.387592 Table repository Column enable_pulls db default is 1, struct default is true
2017/05/02 09:38:42 [xorm] [warn]  2017/05/02 09:38:42.387597 Table repository Column is_fork db default is 0, struct default is false
2017/05/02 09:38:42 [xorm] [warn]  2017/05/02 09:38:42.387751 Table action Column is_private db default is 0, struct default is false
2017/05/02 09:38:42 [xorm] [warn]  2017/05/02 09:38:42.388019 Table mirror Column enable_prune db default is 1, struct default is true
2017/05/02 09:38:42 [xorm] [warn]  2017/05/02 09:38:42.388062 Table release Column is_draft db default is 0, struct default is false
2017/05/02 09:38:42 [xorm] [warn]  2017/05/02 09:38:42.388088 Table login_source Column is_actived db default is 0, struct default is false
```
## Description
Not sure if this is related to https://github.com/gogits/gogs/issues/2786 , but today I was going back to browse the commits I had made last night, and when I tried to view a very small commit I made, gogs hung while trying to load the page and the CPU spiked to 200%. While that was happening I was still able to go to other commits, issues, etc and they loaded at normal speed, it just seems to be something in that specific commit that causes it to hang. I verified that gogs was the culprit when the CPU returned to normal after restarting gogs.

In the commit in question, all I did was make a script executable but didn't change anything else.
```
commit 2cf819b64645c9d2fc95b1272f22e862138ae3e2
Author: xxxx <yyy@example.com>
Date:   Mon May 1 19:38:10 2017 -0500

    fix file mod

diff --git a/storage_info.sh b/storage_info.sh
old mode 100644
new mode 100755
```

Let me know if I can provide anything else, or if I need to upload the repo to https://try.gogs.io for reproduction.
Extremely high CPU usage (200%) when trying to view single commit
issue
created
Unknwon
username_1
Yes, if possible please upload this repository to demo site see we can spot the issue.
comment
created
esayre-um
username_2
I'm having an exceedingly similar issue and can open a separate bug. Essentially we're seeing gogs use 100+% cpu cycle for each thread trying to display a particular couple commits. These were also related to a user attempting to set the mode (execute bit) on a file.
comment
created
Unknwon
username_1
@username_2 thanks for the info!

However I don't seem to be able to understand the "case" you're trying to describe. If possible, the only way to debug this is to upload the exact same repository to demo site and see if problem occurs there. Otherwise it is impossible for me to debug...
comment
created
esayre-um
username_2
Unfortunately our source code is too sensitive for me to push to your public server, however essentially the developer had several commits that were only file mode changes (the developer wanted the execution bit to be set). He had about 6 different commits related to this that he had pushed, but only a couple of them cause Gogs to race trying to display the commit (e.g. … repo .../commit/bbefe6676a36f8cde5e6789487b214b012f9ba82)
comment
created
Unknwon
username_1
There is only one "thread" that parses diff output for a commit page (e.g. `repo .../commit/bbefe6676a36f8cde5e6789487b214b012f9ba82`), so I don't think I'm agree with you.

Does the "race" only and 100% reproducible for that commit (changes file permission)? Or... what?
comment
created
esayre-um
username_2
Yes, it happens every time I try to view the offending commit. If I try more than once it'll elevate CPU usage another 100% or so, which is why I assumed threads. Everything maxes out at 399% CPU so I assume my VM is limited two four processes.
comment
created
esayre-um
username_2
@username_1 is there any debugging logging I can enable?
comment
created
Unknwon
username_1
@username_2 thanks. If you can make a demo repository and does exact same kind of change and push to demo site, would be very helpful to see if it's a general problem or just particular to your VM.
comment
created
esayre-um
username_2
@username_1 wow, I was able to recreate the issue with just 2 commits into a new repo. I've uploaded the repo at https://try.gogs.io/esayre/GogsModeTest/

You can view the offending commit at https://try.gogs.io/esayre/GogsModeTest/commit/0d094c5571df74fe0ddffe22634a45135b06b4bc but beware that it will start the runaway process.
comment
created
Unknwon
username_1
Awesome, I think I know the problem. The code falls into a infinite loop with just mode change (expect some content or file name change).
comment
created
Unknwon
username_1
Patch has pushed to fix this issue, please test on `develop` branch or https://try.gogs.io/esayre/GogsModeTest/commit/0d094c5571df74fe0ddffe22634a45135b06b4bc.
comment
created
esayre-um
username_2
@username_1 thanks. I see it's working fine on try.gogs.io. I only have a productive install here and would rather wait before testing locally. How long do you think before it would make it to the normal release?

I generally install from binary… can I get a binary for the develop branch? If so, can I swap out my Gogs directory temporarily and safely move back to the productive version?
comment
created
Unknwon
username_1
@username_2 not right now.... maybe this weekend but no promise.
comment
created
esayre-um
username_2
@username_1 thanks much. I'll trust since it's resolved on try.gogs.io that it's resolved.
comment
closed
Unknwon
username_1
issue