Browse Source

解决服务ctrl+c关闭慢的问题

tags/v1.22.1.1^2
ychao_1983 3 years ago
parent
commit
4b7f36d52b
2 changed files with 23 additions and 0 deletions
  1. +5
    -0
      services/socketwrap/client.go
  2. +18
    -0
      services/socketwrap/clientManager.go

+ 5
- 0
services/socketwrap/client.go View File

@@ -14,6 +14,11 @@ type Client struct {
Send chan *models.Action
}

func (c *Client) Close() {
close(c.Send)
c.Conn.Close()
}

func (c *Client) WritePump() {

defer func() {


+ 18
- 0
services/socketwrap/clientManager.go View File

@@ -1,7 +1,12 @@
package socketwrap

import (
"os"
"os/signal"
"syscall"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/log"
)

type ClientsManager struct {
@@ -22,6 +27,9 @@ var LastActionsQueue = NewSyncQueue(20)

func (h *ClientsManager) Run() {
initActionQueue()
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
var signalsReceived uint
for {
select {
case client := <-h.Register:
@@ -41,7 +49,17 @@ func (h *ClientsManager) Run() {
delete(h.Clients, client)
}
}
case s := <-sig:
log.Info("received signal", s)
signalsReceived++
if signalsReceived < 2 {
for client, _ := range h.Clients {
delete(h.Clients, client)
client.Close()
}
break

}
}
}
}


Loading…
Cancel
Save