Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stats.DB Index Repo[425] hangs #26064

Closed
somera opened this issue Jul 22, 2023 · 14 comments · Fixed by #26325
Closed

Stats.DB Index Repo[425] hangs #26064

somera opened this issue Jul 22, 2023 · 14 comments · Fixed by #26325
Labels
issue/critical This issue should be fixed ASAP. If it is a PR, the PR should be merged ASAP type/bug

Comments

@somera
Copy link

somera commented Jul 22, 2023

Description

Just saw, that the job hangs.

image
gitea-diagnosis-20230722-235117.zip

Gitea Version

1.20.1

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

No response

Git Version

2.25.1

Operating System

Ubuntu 20.04.6

How are you running Gitea?

Precompiled gitea-1.20.1-linux-amd64

Database

PostgreSQL

@somera
Copy link
Author

somera commented Jul 22, 2023

I restarted my gitea to "fix" this.

@techknowlogick
Copy link
Member

Thanks for the report @somera, could you confirm that repo with ID 425 in your DB is https://github.com/google/material-design-icons ? I'm cloning it now to poke at it in my instance.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Jul 23, 2023

Just a guess, maybe it's related to this problem (I have left some comments in the "code/indexer.go")

This issue's stacktrace:


1 @ 0x440bb6 0x47132c 0x47130c 0x4903ec 0xaa6a5d 0x54833f 0x548f2f 0x549374 0x54974b 0xd60af8 0xdb063b 0x1e56bf8 0x1e576f2 0x1e58a9d 0x1e5b16e 0x1e58729 0x475381
# labels: {"graceful-lifecycle":"with-shutdown", "pid":"64bc45a1", "ppid":"", "process-description":"Stats.DB Index Repo[425]", "process-type":"normal"}
#	0x47130b	sync.runtime_notifyListWait+0x12b							/usr/local/go/src/runtime/sema.go:527
#	0x4903eb	sync.(*Cond).Wait+0x8b									/usr/local/go/src/sync/cond.go:70
#	0xaa6a5c	github.com/djherbis/nio/v3.(*PipeReader).Read+0x19c					/go/pkg/mod/github.com/djherbis/nio/[email protected]/sync.go:106
#	0x54833e	bufio.(*Reader).fill+0xfe								/usr/local/go/src/bufio/bufio.go:106
#	0x548f2e	bufio.(*Reader).ReadSlice+0x2e								/usr/local/go/src/bufio/bufio.go:372
#	0x549373	bufio.(*Reader).collectFragments+0x73							/usr/local/go/src/bufio/bufio.go:447
#	0x54974a	bufio.(*Reader).ReadString+0x2a								/usr/local/go/src/bufio/bufio.go:494
#	0xd60af7	code.gitea.io/gitea/modules/git.ReadBatchLine+0x37					/source/modules/git/batch_reader.go:149
#	0xdb063a	code.gitea.io/gitea/modules/git.(*Repository).GetLanguageStats+0x111a			/source/modules/git/repo_language_stats_nogogit.go:153
#	0x1e56bf7	code.gitea.io/gitea/modules/indexer/stats.(*DBIndexer).Index+0x5b7			/source/modules/indexer/stats/db.go:64
#	0x1e576f1	code.gitea.io/gitea/modules/indexer/stats.handler+0x71					/source/modules/indexer/stats/queue.go:22
#	0x1e58a9c	code.gitea.io/gitea/modules/queue.NewWorkerPoolQueueWithContext[...].func1+0x9c		/source/modules/queue/workerqueue.go:246
#	0x1e5b16d	code.gitea.io/gitea/modules/queue.(*WorkerPoolQueue[...]).doWorkerHandle+0x16d		/source/modules/queue/workergroup.go:98
#	0x1e58728	code.gitea.io/gitea/modules/queue.(*WorkerPoolQueue[...]).doStartNewWorker.func1+0x308	/source/modules/queue/workergroup.go:162

Previous comment:

image

@somera
Copy link
Author

somera commented Jul 23, 2023

Thanks for the report @somera, could you confirm that repo with ID 425 in your DB is https://github.com/google/material-design-icons ? I'm cloning it now to poke at it in my instance.

Yes, this repo is in my DB.

@somera
Copy link
Author

somera commented Jul 31, 2023

1.20.2: hangs for 2 hours now.

image

gitea-diagnosis-20230731-181943.zip

@wxiaoguang
Copy link
Contributor

Still the same problem as above: stats.(*DBIndexer).Index -> GetLanguageStats -> git.ReadBatchLine ....

I have tried writing some different tests but I still can't reproduce it on my side, no idea yet .....

@somera
Copy link
Author

somera commented Jul 31, 2023

I think this happens, when the mirror and stats tasks run at the same time. But i'm not sure, that this is the reason.

@somera
Copy link
Author

somera commented Jul 31, 2023

And I found

2023/07/31 16:10:59 ...it/repo_attribute.go:306:func2() [E] Unable to open checker for 6745d95590b1a5593888b6c402401fc3db75fbdb. Error: failed to run attr-check. Error: context deadline exceeded
Stderr:
        /source/modules/git/repo_attribute.go:306 (0xd8e2e1)
        /usr/local/go/src/runtime/asm_amd64.s:1598 (0x475380)
                goexit: BYTE    $0x90   // NOP

@somera
Copy link
Author

somera commented Jul 31, 2023

And I see, this is the same repo id -> 425.

@somera
Copy link
Author

somera commented Aug 3, 2023

I removed the mirror.

The issue can be closed or you fix this: #26064 (comment)

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Aug 4, 2023

I think it is a really serious bug, so it could be kept open until it gets resolved ......

ps: the repo contains a lot of small files (580937) , https://github.com/google/material-design-icons

@lunny lunny added the issue/critical This issue should be fixed ASAP. If it is a PR, the PR should be merged ASAP label Aug 4, 2023
@wxiaoguang
Copy link
Contributor

As a workaround:

;; repo indexer units, the items to index, could be `sources`, `forks`, `mirrors`, `templates` or any combination of them separated by a comma.
;; If empty then it defaults to `sources` only, as if you'd like to disable fully please see REPO_INDEXER_ENABLED.
;REPO_INDEXER_REPO_TYPES = sources,forks,mirrors,templates

I think it could help you to avoid indexing such large repo

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Aug 4, 2023

After more trails, I figured out the problem. It looks like a Golang's framework's bug flaw (although it has been documented but not obvious ....).

Demo code:

func TestCommand(t *testing.T) {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	cmd := exec.CommandContext(ctx, "cat")
	rStdin, wStdin := io.Pipe()
	rStdout, wStdout := io.Pipe() // nio.Pipe(buffer.New(32 * 1024))
	cmd.Stdin = rStdin
	cmd.Stdout = wStdout
	written := 0
	read := 0
	stopWriting := atomic.Bool{}
	go func() {
		for !stopWriting.Load() {
			line := strings.Repeat("a", 5+rand.Intn(100)) + "\n"
			for i := 0; i < len(line); i++ {
				_, _ = wStdin.Write([]byte{line[i]})
			}
			written++
			time.Sleep(50 * time.Microsecond)
		}
	}()
	go func() {
		bio := bufio.NewReader(rStdout)
		for {
			_, _ = bio.ReadString('\n')
			read++
		}
	}()

	go func() {
		time.Sleep(1000 * time.Millisecond)
		t.Logf("now written: %d, read: %d, stop writing", written, read)
		stopWriting.Store(true) // with this line, if the "writing" is stopped ahead, the cmd.Run()/Wait() gets stuck forever
		t.Logf("cancel context (kill process) ...")
		cancel()
	}()

	err := cmd.Run()
	assert.Error(t, err)
	t.Logf("done. written: %d, read: %d", written, read)
}

Update: Hmm .... OK, actually, not Golang's bug, it's a Golang's design flaw ..... the Stdin/Stdout should not be used that way.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Aug 4, 2023

And one more thing, after #26325 gets merged, you might see your mirror tasks consume more CPU

Before: the mirror's tasks like "language stats" runs with CPU=100% and fails after 10minute timeout

After: the tasks won't fail by timeout, it will try to run as long as possible to finish the "language stats" task, for the "material-design-icons" repo which has more than 580k files, it will run for a pretty long time with CPU=100%. The good news is that the "languages stats" will be right then.

KN4CK3R pushed a commit that referenced this issue Aug 4, 2023
…lt timeout (#26325)

Fix #26064

Some git commands should use parent context, otherwise it would exit too
early (by the default timeout, 10m), and the "cmd.Wait" waits till the
pipes are closed.
GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue Aug 4, 2023
…lt timeout (go-gitea#26325)

Fix go-gitea#26064

Some git commands should use parent context, otherwise it would exit too
early (by the default timeout, 10m), and the "cmd.Wait" waits till the
pipes are closed.
delvh pushed a commit that referenced this issue Aug 4, 2023
…lt timeout (#26325) (#26330)

Backport #26325 by @wxiaoguang

Fix #26064

Some git commands should use parent context, otherwise it would exit too
early (by the default timeout, 10m), and the "cmd.Wait" waits till the
pipes are closed.

Co-authored-by: wxiaoguang <[email protected]>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 19, 2023
project-mirrors-bot-tu bot pushed a commit to project-mirrors/forgejo-as-gitea-fork that referenced this issue Jan 23, 2025
…lt timeout (go-gitea#26325) (go-gitea#26330)

Backport go-gitea#26325 by @wxiaoguang

Fix go-gitea#26064

Some git commands should use parent context, otherwise it would exit too
early (by the default timeout, 10m), and the "cmd.Wait" waits till the
pipes are closed.

Co-authored-by: wxiaoguang <[email protected]>
(cherry picked from commit 9451781)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/critical This issue should be fixed ASAP. If it is a PR, the PR should be merged ASAP type/bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants