Skip to content

Commit

Permalink
fix: clear session before quit (#121)
Browse files Browse the repository at this point in the history
mod: code review

mod: code review
  • Loading branch information
hetao92 authored Jun 27, 2022
1 parent 0bca4d0 commit d7a7667
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
16 changes: 11 additions & 5 deletions ccore/nebula/gateway/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ var (

// Console side commands
const (
Unknown = -1
Param = 1
Params = 2
clientRecycleNum = 30
clientMaxNum = 200
Unknown = -1
Param = 1
Params = 2
clientRecycleNum = 30
clientMaxNum = 200
SessionExpiredDuration int64 = 3600
)

Expand Down Expand Up @@ -266,6 +266,12 @@ func NewClient(address string, port int, username string, password string, opts
return info, err
}

func ClearClients() {
for _, client := range clientPool {
client.graphClient.Close()
}
}

func recycleClients() {
for _, client := range clientPool {
now := time.Now().Unix()
Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import (
"syscall"
"time"

"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"github.com/vesoft-inc/nebula-http-gateway/common"
_ "github.com/vesoft-inc/nebula-http-gateway/routers"

"github.com/astaxie/beego"
"github.com/vesoft-inc/nebula-http-gateway/common"
"github.com/vesoft-inc/nebula-http-gateway/ccore/nebula/gateway/pool"
)

func main() {
Expand Down Expand Up @@ -98,7 +99,7 @@ func main() {

ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()

pool.ClearClients()
beego.BeeApp.Server.SetKeepAlivesEnabled(false)
if err := beego.BeeApp.Server.Shutdown(ctx); err != nil {
logs.Error(err.Error())
Expand Down

0 comments on commit d7a7667

Please sign in to comment.