houstonClient 종료시 houstonServer도 종료
This commit is contained in:
@ -15,10 +15,6 @@ import (
|
|||||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
defaultMaxMemory = 32 << 10 // 32 KB
|
|
||||||
)
|
|
||||||
|
|
||||||
type HoustonServerWithHandler interface {
|
type HoustonServerWithHandler interface {
|
||||||
HoustonServer
|
HoustonServer
|
||||||
RegisterHandlers(serveMux *http.ServeMux, prefix string) error
|
RegisterHandlers(serveMux *http.ServeMux, prefix string) error
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||||
@ -176,23 +177,35 @@ func (hs *houstonServer) Start() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closeCount := int32(0)
|
||||||
|
var hc client.HoustonClient
|
||||||
if loadServerConfig().RunAsClient {
|
if loadServerConfig().RunAsClient {
|
||||||
|
hc, err = client.NewClient()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
hc, err := client.NewClient()
|
|
||||||
if err != nil {
|
|
||||||
logger.Fatal(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
hc.Start()
|
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 {
|
err = hs.rpcServer.Serve(lis)
|
||||||
return err
|
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() {
|
func (hs *houstonServer) Stop() {
|
||||||
|
|||||||
Reference in New Issue
Block a user