diff --git a/go.mod b/go.mod index 8940446..bb38978 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/golang/protobuf v1.5.4 github.com/google/uuid v1.6.0 github.com/hashicorp/errwrap v1.1.0 // indirect - github.com/polarismesh/polaris-go v1.6.0-beta.4 + github.com/polarismesh/polaris-go v1.6.0-beta.5 github.com/polarismesh/specification v1.5.1 github.com/prometheus/client_golang v1.19.1 // indirect github.com/prometheus/common v0.54.0 // indirect diff --git a/go.sum b/go.sum index 5645866..9b3bd80 100644 --- a/go.sum +++ b/go.sum @@ -1695,8 +1695,8 @@ github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZ github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/polarismesh/polaris-go v1.6.0-beta.4 h1:II1PVHU9NJtbzZcZj6MMQH7tYjjUrxJQDu9x1dOYhdk= -github.com/polarismesh/polaris-go v1.6.0-beta.4/go.mod h1:CuXO9bhHGjSoOIMWr4NXf3bJAkRBp5YoM7ibBzENC+c= +github.com/polarismesh/polaris-go v1.6.0-beta.5 h1:llucvfydWlFWTNeABHbbuVL2ijR7AITx8UG02tx0c/Y= +github.com/polarismesh/polaris-go v1.6.0-beta.5/go.mod h1:CuXO9bhHGjSoOIMWr4NXf3bJAkRBp5YoM7ibBzENC+c= github.com/polarismesh/specification v1.4.1/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU= github.com/polarismesh/specification v1.5.1 h1:cJ2m0RBepdopGo/e3UpKdsab3NpDZnw5IsVTB1sFc5I= github.com/polarismesh/specification v1.5.1/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU= diff --git a/server.go b/server.go index 089901b..71e9499 100644 --- a/server.go +++ b/server.go @@ -26,6 +26,7 @@ import ( "os/signal" "strconv" "strings" + "sync/atomic" "syscall" "time" @@ -42,6 +43,7 @@ type Server struct { sdkCtx api.SDKContext providerAPI api.ProviderAPI registerRequests []*api.InstanceRegisterRequest + isStop int32 } // NewServer start polaris server @@ -126,7 +128,7 @@ func (srv *Server) Serve(lis net.Listener) error { go func() { c := make(chan os.Signal, 1) - signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) + signal.Notify(c, syscall.SIGSEGV, syscall.SIGINT, syscall.SIGTERM) s := <-c log.Printf("[Polaris][Naming] receive quit signal: %v", s) signal.Stop(c) @@ -138,6 +140,10 @@ func (srv *Server) Serve(lis net.Listener) error { // Stop deregister and stop func (srv *Server) Stop() { + if !atomic.CompareAndSwapInt32(&srv.isStop, 0, 1) { + return + } + srv.Deregister() if !*srv.serverOptions.gracefulStopEnable {