Skip to content

Data race when terminating the progress #27643

Closed
@Lantern-r

Description

@Lantern-r

Description

lantern@SaaS:/Users/lantern/Documents/GitHub/gitea$ ./gitea web
2023/10/16 20:05:22 cmd/web.go:242:runWeb() [I] Starting Gitea on PID: 211
2023/10/16 20:05:22 cmd/web.go:111:showWebStartupMessage() [I] Gitea version: development built with go1.21.3
2023/10/16 20:05:22 cmd/web.go:112:showWebStartupMessage() [I] * RunMode: prod
2023/10/16 20:05:22 cmd/web.go:113:showWebStartupMessage() [I] * AppPath: /Users/lantern/Documents/GitHub/gitea/gitea_race
2023/10/16 20:05:22 cmd/web.go:114:showWebStartupMessage() [I] * WorkPath: /Users/lantern/Documents/GitHub/gitea
2023/10/16 20:05:22 cmd/web.go:115:showWebStartupMessage() [I] * CustomPath: /Users/lantern/Documents/GitHub/gitea/custom
2023/10/16 20:05:22 cmd/web.go:116:showWebStartupMessage() [I] * ConfigFile: /Users/lantern/Documents/GitHub/gitea/custom/conf/app.ini
2023/10/16 20:05:22 cmd/web.go:117:showWebStartupMessage() [I] Prepare to run install page
2023/10/16 20:05:23 cmd/web.go:304:listen() [I] Listen: http://0.0.0.0:3000
2023/10/16 20:05:23 cmd/web.go:308:listen() [I] AppURL(ROOT_URL): http://localhost:3000/
2023/10/16 20:05:23 ...s/graceful/server.go:70:NewServer() [I] Starting new Web server: tcp:0.0.0.0:3000 on PID: 211
^C2023/10/16 20:05:25 ...eful/manager_unix.go:195:handleSignals() [W] PID 211. Received SIGINT. Shutting down...
2023/10/16 20:05:25 ...eful/server_hooks.go:46:doShutdown() [I] PID: 211 Listener ([::]:3000) closed.
==================
WARNING: DATA RACE
Write at 0x00c0000b0be0 by goroutine 38:
  runtime.racewrite()
      <autogenerated>:1 +0x1e
  code.gitea.io/gitea/modules/graceful.(*Manager).WaitForServers()
      /Users/lantern/Documents/GitHub/gitea/modules/graceful/manager.go:232 +0x56
  code.gitea.io/gitea/modules/graceful.(*Manager).doShutdown.func1()
      /Users/lantern/Documents/GitHub/gitea/modules/graceful/manager.go:150 +0x4e

Previous read at 0x00c0000b0be0 by main goroutine:
  runtime.raceread()
      <autogenerated>:1 +0x1e
  code.gitea.io/gitea/modules/graceful.(*Manager).RegisterServer()
      /Users/lantern/Documents/GitHub/gitea/modules/graceful/manager_unix.go:282 +0x54
  code.gitea.io/gitea/modules/graceful.(*Server).Serve()
      /Users/lantern/Documents/GitHub/gitea/modules/graceful/server.go:174 +0xe9
  code.gitea.io/gitea/modules/graceful.(*Server).ListenAndServe()
      /Users/lantern/Documents/GitHub/gitea/modules/graceful/server.go:115 +0x4d8
  code.gitea.io/gitea/modules/graceful.HTTPListenAndServe()
      /Users/lantern/Documents/GitHub/gitea/modules/graceful/server_http.go:32 +0x9d
  code.gitea.io/gitea/cmd.runHTTP()
      /Users/lantern/Documents/GitHub/gitea/cmd/web_graceful.go:18 +0xa33
  code.gitea.io/gitea/cmd.listen()
      /Users/lantern/Documents/GitHub/gitea/cmd/web.go:320 +0x9e5
  code.gitea.io/gitea/cmd.serveInstall()
      /Users/lantern/Documents/GitHub/gitea/cmd/web.go:137 +0x10c
  code.gitea.io/gitea/cmd.runWeb()
      /Users/lantern/Documents/GitHub/gitea/cmd/web.go:251 +0x313
  code.gitea.io/gitea/cmd.prepareSubcommandWithConfig.prepareWorkPathAndCustomConf.func1()
      /Users/lantern/Documents/GitHub/gitea/cmd/main.go:117 +0x28d
  github.com/urfave/cli/v2.(*Command).Run()
      /home/lantern/go/pkg/mod/github.com/urfave/cli/[email protected]/command.go:274 +0x1334
  github.com/urfave/cli/v2.(*Command).Run()
      /home/lantern/go/pkg/mod/github.com/urfave/cli/[email protected]/command.go:267 +0x120b
  github.com/urfave/cli/v2.(*App).RunContext()
      /home/lantern/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:332 +0x1249
  github.com/urfave/cli/v2.(*App).Run()
      /home/lantern/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:309 +0x64
  code.gitea.io/gitea/cmd.RunMainApp()
      /Users/lantern/Documents/GitHub/gitea/cmd/main.go:176 +0x36
  main.main()
      /Users/lantern/Documents/GitHub/gitea/main.go:46 +0xb5

Goroutine 38 (running) created at:
  code.gitea.io/gitea/modules/graceful.(*Manager).doShutdown()
      /Users/lantern/Documents/GitHub/gitea/modules/graceful/manager.go:149 +0x4f3
  code.gitea.io/gitea/modules/graceful.(*Manager).DoGracefulShutdown()
      /Users/lantern/Documents/GitHub/gitea/modules/graceful/manager_unix.go:273 +0xf2
  code.gitea.io/gitea/modules/graceful.(*Manager).handleSignals()
      /Users/lantern/Documents/GitHub/gitea/modules/graceful/manager_unix.go:196 +0x6a4
  code.gitea.io/gitea/modules/graceful.(*Manager).start.func4()
      /Users/lantern/Documents/GitHub/gitea/modules/graceful/manager_unix.go:113 +0x4f
==================
2023/10/16 20:05:25 cmd/web.go:355:listen() [I] HTTP Listener: 0.0.0.0:3000 Closed
2023/10/16 20:05:25 .../graceful/manager.go:168:doHammerTime() [W] Setting Hammer condition
2023/10/16 20:05:26 .../graceful/manager.go:184:doTerminate() [W] Terminating
2023/10/16 20:05:26 ...eful/manager_unix.go:208:handleSignals() [W] PID: 211. Background context for manager closed - context canceled - Shutting down...
2023/10/16 20:05:26 cmd/web.go:145:serveInstall() [I] PID: 211 Gitea Web Finished

git brach: main

lantern@SaaS:/Users/lantern/Documents/GitHub/gitea$ git branch
* main

possible fix:

gitea/modules/graceful/manager.go:232

func (g *Manager) WaitForServers() {
	g.lock.Lock() // add lock and unlock
	defer g.lock.Unlock()
	g.runningServerWaitGroup.Wait()
}

gitea/modules/graceful/manager_unix.go:280

func (g *Manager) RegisterServer() {
	KillParent()
	g.lock.Lock() // add lock and lock
	defer g.lock.Unlock()
	g.runningServerWaitGroup.Add(1)
}

Gitea Version

Gitea version development built with go1.21.3

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

ubuntu 22.04

./gitea web

Database

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions