Skip to content

Conversation

lunny
Copy link
Member

@lunny lunny commented Oct 15, 2025

This PR fixes a panic issue in the WaitGroup that occurs when Gitea is shut down using Ctrl+C.
It ensures that all active connection pointers in the server are properly tracked and forcibly closed when the hammer shutdown is invoked.
The process remains graceful — the normal shutdown sequence runs before the hammer is triggered, and existing connections are given a timeout period to complete gracefully.

This PR also fixes no logger writer problem. Now the log close will only be invoked when the command exit.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Oct 15, 2025
@lunny lunny added type/bug and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Oct 15, 2025
@github-actions github-actions bot added modifies/go Pull requests that update Go code modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin labels Oct 15, 2025
@lunny lunny added backport/v1.25 and removed modifies/go Pull requests that update Go code modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin labels Oct 15, 2025
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Oct 15, 2025

  1. Fixes #35648 seems to be a wrong reference, 35648 is for OAuth2
  2. I don't think it's right to keep doing "// Check for shutdown signal during startup", the "shutdown" can occur exactly after your check, then the check doesn't really help anything.
  3. For the connections, if you decided to use "connections map", what does wl.server.wg.Add(1) do? Does it still make sense?
    • wg.Wait is used for waiting for the open connections, so it is still useful (BUT not right)
    • Maybe the Add-After-Wait data-race still exists (much more rare than before, better than before): doShutdown -> setState(stateShuttingDown) -> new conn comes -> listener.Close() -> wg.Wait() -> new conn wg.Add()

@lunny
Copy link
Member Author

lunny commented Oct 16, 2025

  1. Fixes #35648 seems to be a wrong reference, 35648 is for OAuth2

  2. I don't think it's right to keep doing "// Check for shutdown signal during startup", the "shutdown" can occur exactly after your check, then the check doesn't really help anything.

  3. For the connections, if you decided to use "connections map", what does wl.server.wg.Add(1) do? Does it still make sense?

    • wg.Wait is used for waiting for the open connections, so it is still useful
    • Maybe the Add-After-Wait data-race still exists (much more rare than before, better than before): doShutdown -> setState(stateShuttingDown) -> new conn comes -> listener.Close() -> wg.Wait() -> new conn wg.Add()


// Close all connections outside the lock to avoid deadlock
for _, conn := range connections {
_ = conn.Conn.Close() // Force close the underlying connection
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not right, you can't close "underlying", you must close the conn itself.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Oct 16, 2025
@github-actions github-actions bot added modifies/go Pull requests that update Go code modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin labels Oct 16, 2025
}
app := cmd.NewMainApp(cmd.AppVersion{Version: Version, Extra: formatBuiltWith()})
_ = cmd.RunMainApp(app, os.Args...) // all errors should have been handled by the RunMainApp
log.GetManager().Close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is right. Are you sure cli.OsExiter is always called?

@wxiaoguang wxiaoguang force-pushed the lunny/fix_shutdown_issue branch from 45d862c to b70d961 Compare October 16, 2025 01:37
@wxiaoguang wxiaoguang marked this pull request as draft October 16, 2025 01:37
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Oct 16, 2025

The checking could check the situation ctrl+c before web listening. I can try to reduce them.

You can reproduce doesn't mean the fix is right.

Once listener closed, there should be no new connection coming.

I am showing the "DATA-RACE". "listener.Close" and "Accept" are in different threads.

Anyway, talk is cheap, I showed you my code.

@wxiaoguang wxiaoguang force-pushed the lunny/fix_shutdown_issue branch from b70d961 to 035aa77 Compare October 16, 2025 01:43
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Oct 16, 2025

This PR also fixes no logger writer problem. Now the log close will only be invoked when the command exit.
Fixes [no logger writer]: Queue "repo-archive" stops running #35551

Your change is also wrong. I have told you the root problem and it is not easy to fix. #35551 (comment)

@wxiaoguang wxiaoguang marked this pull request as ready for review October 16, 2025 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin modifies/go Pull requests that update Go code type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ctrl+C result in panic [no logger writer]: Queue "repo-archive" stops running Ctrl +C shudown Gitea caused WaitGroup panic

3 participants