Skip to content

Commit 64f85ed

Browse files
committed
fix comment and code, fix lint
1 parent 95bca65 commit 64f85ed

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

modules/graceful/manager.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,15 @@ func InitManager(ctx context.Context) {
6060
})
6161
}
6262

63-
// RunWithCancel helps to run a function with a custom context, the cancel function will be called at shutdown
63+
// RunWithCancel helps to run a function with a custom context, the Cancel function will be called at shutdown
64+
// The Cancel function should stop the Run function in predictable time.
6465
func (g *Manager) RunWithCancel(rc RunCanceler) {
6566
g.RunAtShutdown(context.Background(), rc.Cancel)
6667
g.runningServerWaitGroup.Add(1)
6768
defer g.runningServerWaitGroup.Done()
6869
defer func() {
6970
if err := recover(); err != nil {
70-
log.Critical("PANIC during RunWithCustomContext: %v\nStacktrace: %s", err, log.Stack(2))
71+
log.Critical("PANIC during RunWithCancel: %v\nStacktrace: %s", err, log.Stack(2))
7172
g.doShutdown()
7273
}
7374
}()

modules/log/event_writer_base.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ func (b *EventWriterBaseImpl) GetLevel() Level {
5858

5959
// Run is the default implementation for EventWriter.Run
6060
func (b *EventWriterBaseImpl) Run(ctx context.Context) {
61-
pprof.SetGoroutineLabels(ctx)
62-
6361
defer b.OutputWriteCloser.Close()
6462

6563
var exprRegexp *regexp.Regexp
@@ -155,6 +153,7 @@ func eventWriterStartGo(ctx context.Context, w EventWriter, shared bool) {
155153
go func() {
156154
defer writerCancel()
157155
defer close(w.Base().stopped)
156+
pprof.SetGoroutineLabels(writerCtx)
158157
w.Run(writerCtx)
159158
}()
160159
}

modules/log/init.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ import (
1313
"code.gitea.io/gitea/modules/util/rotatingfilewriter"
1414
)
1515

16-
var projectPackagePrefix string
17-
var processTraceDisabled atomic.Int64
16+
var (
17+
projectPackagePrefix string
18+
processTraceDisabled atomic.Int64
19+
)
1820

1921
func init() {
2022
_, filename, _, _ := runtime.Caller(0)

modules/notification/ui/ui.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func handler(items ...issueNotificationOpts) []issueNotificationOpts {
5454
}
5555

5656
func (ns *notificationService) Run() {
57-
graceful.GetManager().RunWithCancel(ns.issueQueue)
57+
go graceful.GetManager().RunWithCancel(ns.issueQueue) // TODO: using "go" here doesn't seem right, just leave it as old code
5858
}
5959

6060
func (ns *notificationService) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,

modules/queue/workerqueue.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ type WorkerPoolQueue[T any] struct {
2323
ctxRun context.Context
2424
ctxRunCancel context.CancelFunc
2525

26-
// ctxShutdown atomic.Pointer[context.Context]
2726
shutdownDone chan struct{}
28-
shutdownTimeout atomic.Int64
27+
shutdownTimeout atomic.Int64 // in case some buggy handlers (workers) would hang forever, "shutdown" should finish in predictable time
2928

3029
origHandler HandlerFuncT[T]
3130
safeHandler HandlerFuncT[T]

0 commit comments

Comments
 (0)