houstonClient 종료시 houstonServer도 종료

This commit is contained in:
2023-06-29 10:19:57 +09:00
parent 6a35d7b1fe
commit cf46888b6a
2 changed files with 21 additions and 12 deletions

View File

@ -15,10 +15,6 @@ import (
"repositories.action2quare.com/ayo/gocommon/logger"
)
const (
defaultMaxMemory = 32 << 10 // 32 KB
)
type HoustonServerWithHandler interface {
HoustonServer
RegisterHandlers(serveMux *http.ServeMux, prefix string) error

View File

@ -5,6 +5,7 @@ import (
"fmt"
"net"
"os"
"sync/atomic"
"time"
"repositories.action2quare.com/ayo/gocommon/logger"
@ -176,23 +177,35 @@ func (hs *houstonServer) Start() error {
return err
}
closeCount := int32(0)
var hc client.HoustonClient
if loadServerConfig().RunAsClient {
hc, err = client.NewClient()
if err != nil {
return err
}
go func() {
time.Sleep(time.Second)
hc, err := client.NewClient()
if err != nil {
logger.Fatal(err)
return
}
hc.Start()
logger.Println("houstonClient is finished")
if atomic.AddInt32(&closeCount, 1) == 1 {
logger.Println("try stop houstonServer")
hs.Stop()
}
}()
}
if err := hs.rpcServer.Serve(lis); err != nil {
return err
err = hs.rpcServer.Serve(lis)
if atomic.AddInt32(&closeCount, 1) == 1 {
if hc != nil {
logger.Println("try stop houstonClient")
hc.Shutdown()
}
}
logger.Println("houstonServer is finished")
return nil
return err
}
func (hs *houstonServer) Stop() {