Skip to content
Snippets Groups Projects
Commit 43e024f8 authored by lzp0412's avatar lzp0412
Browse files

fix not invoke nacos destroy when graceful shutdown

parent 0f72a576
No related branches found
No related tags found
No related merge requests found
......@@ -26,7 +26,7 @@ var (
// ShutdownSignals ...
ShutdownSignals = []os.Signal{os.Interrupt, os.Kill, syscall.SIGKILL, syscall.SIGSTOP,
syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGILL, syscall.SIGTRAP,
syscall.SIGABRT, syscall.SIGSYS}
syscall.SIGABRT, syscall.SIGSYS, syscall.SIGTERM}
// DumpHeapShutdownSignals ...
DumpHeapShutdownSignals = []os.Signal{syscall.SIGQUIT, syscall.SIGILL,
......
......@@ -117,7 +117,7 @@ func newNacosRegistry(url *common.URL) (registry.Registry, error) {
registry := nacosRegistry{
URL: url,
namingClient: client,
registryUrls: make([]common.URL, 16, 16),
registryUrls: []common.URL{},
}
return &registry, nil
}
......@@ -267,9 +267,9 @@ func (nr *nacosRegistry) IsAvailable() bool {
}
func (nr *nacosRegistry) Destroy() {
logger.Info("Destroy nacos")
for _, url := range nr.registryUrls {
err := nr.DeRegister(url)
logger.Infof("DeRegister Nacos url:%+v", url)
if err != nil {
logger.Errorf("Deregister url:%+v err:%v", url, err.Error())
}
......
......@@ -44,6 +44,7 @@ import (
)
var (
once sync.Once
regProtocol *registryProtocol
)
......@@ -154,6 +155,7 @@ func (proto *registryProtocol) Export(invoker protocol.Invoker) protocol.Exporte
if regI, loaded := proto.registries.Load(registryUrl.Key()); !loaded {
reg = getRegistry(registryUrl)
proto.registries.Store(registryUrl.Key(), reg)
logger.Infof("Export proto:%p registries address:%p", proto, proto.registries)
} else {
reg = regI.(registry.Registry)
}
......@@ -307,14 +309,12 @@ func (proto *registryProtocol) Destroy() {
ivk.Destroy()
}
proto.invokers = []protocol.Invoker{}
proto.bounds.Range(func(key, value interface{}) bool {
exporter := value.(protocol.Exporter)
exporter.Unexport()
proto.bounds.Delete(key)
return true
})
proto.registries.Range(func(key, value interface{}) bool {
reg := value.(registry.Registry)
if reg.IsAvailable() {
......@@ -348,11 +348,11 @@ func setProviderUrl(regURL *common.URL, providerURL *common.URL) {
// GetProtocol ...
func GetProtocol() protocol.Protocol {
if regProtocol != nil {
once.Do(func() {
regProtocol = newRegistryProtocol()
})
return regProtocol
}
return newRegistryProtocol()
}
type wrappedInvoker struct {
invoker protocol.Invoker
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment