@@ -63,11 +63,12 @@ func gracefulShutdownInit() {
6363 if ! exist {
6464 return
6565 }
66- if filter , ok := gracefulShutdownConsumerFilter .(Setter ); ok && rootConfig .Shutdown != nil {
66+ rc := GetRootConfig ()
67+ if filter , ok := gracefulShutdownConsumerFilter .(Setter ); ok && rc != nil && rc .Shutdown != nil {
6768 filter .Set (constant .GracefulShutdownFilterShutdownConfig , GetShutDown ())
6869 }
6970
70- if filter , ok := gracefulShutdownProviderFilter .(Setter ); ok && rootConfig .Shutdown != nil {
71+ if filter , ok := gracefulShutdownProviderFilter .(Setter ); ok && rc != nil && rc .Shutdown != nil {
7172 filter .Set (constant .GracefulShutdownFilterShutdownConfig , GetShutDown ())
7273 }
7374
@@ -127,21 +128,22 @@ func destroyAllRegistries() {
127128func destroyProtocols () {
128129 logger .Info ("Graceful shutdown --- Destroy protocols. " )
129130
130- if rootConfig .Protocols == nil {
131+ rc := GetRootConfig ()
132+ if rc == nil || rc .Protocols == nil {
131133 return
132134 }
133135
134- consumerProtocols := getConsumerProtocols ()
136+ consumerProtocols := getConsumerProtocols (rc )
135137
136- destroyProviderProtocols (consumerProtocols )
138+ destroyProviderProtocols (rc , consumerProtocols )
137139 destroyConsumerProtocols (consumerProtocols )
138140}
139141
140142// destroyProviderProtocols destroys the provider's protocol.
141143// if the protocol is consumer's protocol too, we will keep it
142- func destroyProviderProtocols (consumerProtocols * gxset.HashSet ) {
144+ func destroyProviderProtocols (rc * RootConfig , consumerProtocols * gxset.HashSet ) {
143145 logger .Info ("Graceful shutdown --- First destroy provider's protocols. " )
144- for _ , protocol := range rootConfig .Protocols {
146+ for _ , protocol := range rc .Protocols {
145147 // the protocol is the consumer's protocol too, we can not destroy it.
146148 if consumerProtocols .Contains (protocol .Name ) {
147149 continue
@@ -159,18 +161,19 @@ func destroyConsumerProtocols(consumerProtocols *gxset.HashSet) {
159161
160162func waitAndAcceptNewRequests () {
161163 logger .Info ("Graceful shutdown --- Keep waiting and accept new requests for a short time. " )
162- if rootConfig .Shutdown == nil {
164+ rc := GetRootConfig ()
165+ if rc == nil || rc .Shutdown == nil {
163166 return
164167 }
165168
166- time .Sleep (rootConfig .Shutdown .GetConsumerUpdateWaitTime ())
169+ time .Sleep (rc .Shutdown .GetConsumerUpdateWaitTime ())
167170
168- timeout := rootConfig .Shutdown .GetStepTimeout ()
171+ timeout := rc .Shutdown .GetStepTimeout ()
169172 // ignore this step
170173 if timeout < 0 {
171174 return
172175 }
173- waitingProviderProcessedTimeout (rootConfig .Shutdown )
176+ waitingProviderProcessedTimeout (rc .Shutdown )
174177}
175178
176179func waitingProviderProcessedTimeout (shutdownConfig * ShutdownConfig ) {
@@ -193,12 +196,13 @@ func waitingProviderProcessedTimeout(shutdownConfig *ShutdownConfig) {
193196// for provider. It will wait for processing receiving requests
194197func waitForSendingAndReceivingRequests () {
195198 logger .Info ("Graceful shutdown --- Keep waiting until sending/accepting requests finish or timeout. " )
196- if rootConfig == nil || rootConfig .Shutdown == nil {
199+ rc := GetRootConfig ()
200+ if rc == nil || rc .Shutdown == nil {
197201 // ignore this step
198202 return
199203 }
200- rootConfig .Shutdown .RejectRequest .Store (true )
201- waitingConsumerProcessedTimeout (rootConfig .Shutdown )
204+ rc .Shutdown .RejectRequest .Store (true )
205+ waitingConsumerProcessedTimeout (rc .Shutdown )
202206}
203207
204208func waitingConsumerProcessedTimeout (shutdownConfig * ShutdownConfig ) {
@@ -217,21 +221,22 @@ func waitingConsumerProcessedTimeout(shutdownConfig *ShutdownConfig) {
217221
218222func totalTimeout () time.Duration {
219223 timeout := defaultShutDownTime
220- if rootConfig .Shutdown != nil && rootConfig .Shutdown .GetTimeout () > timeout {
221- timeout = rootConfig .Shutdown .GetTimeout ()
224+ rc := GetRootConfig ()
225+ if rc != nil && rc .Shutdown != nil && rc .Shutdown .GetTimeout () > timeout {
226+ timeout = rc .Shutdown .GetTimeout ()
222227 }
223228
224229 return timeout
225230}
226231
227232// we can not get the protocols from consumerConfig because some protocol don't have configuration, like jsonrpc.
228- func getConsumerProtocols () * gxset.HashSet {
233+ func getConsumerProtocols (rc * RootConfig ) * gxset.HashSet {
229234 result := gxset .NewSet ()
230- if rootConfig .Consumer == nil || rootConfig .Consumer .References == nil {
235+ if rc == nil || rc .Consumer == nil || rc .Consumer .References == nil {
231236 return result
232237 }
233238
234- for _ , reference := range rootConfig .Consumer .References {
239+ for _ , reference := range rc .Consumer .References {
235240 result .Add (reference .Protocol )
236241 }
237242 return result
0 commit comments