@@ -116,7 +116,7 @@ func (cp *ConsulClient) RegisterService(serviceInfo ServiceInfo) error {
116
116
117
117
// Run refresh in background
118
118
stopChan := make (chan struct {})
119
- go cp .client . Session (). RenewPeriodic ( sessCfg .TTL , sessionID , nil , stopChan )
119
+ go cp .renewService ( keyName , sessCfg .TTL , sessionID , stopChan )
120
120
121
121
// Store it in DB
122
122
cp .serviceDb [keyName ] = & consulServiceState {
@@ -240,6 +240,8 @@ func (cp *ConsulClient) DeregisterService(serviceInfo ServiceInfo) error {
240
240
return errors .New ("Service not found" )
241
241
}
242
242
243
+ log .Infof ("Deregistering service key: %s, value: %+v" , keyName , serviceInfo )
244
+
243
245
// stop the refresh thread and delete service
244
246
close (srvState .stopChan )
245
247
delete (cp .serviceDb , keyName )
@@ -255,6 +257,16 @@ func (cp *ConsulClient) DeregisterService(serviceInfo ServiceInfo) error {
255
257
}
256
258
257
259
//--------------------- Internal funcitons -------------------
260
+ func (cp * ConsulClient ) renewService (keyName , ttl , sessionID string , stopChan chan struct {}) {
261
+ for {
262
+ err := cp .client .Session ().RenewPeriodic (ttl , sessionID , nil , stopChan )
263
+ if err == nil {
264
+ log .Infof ("Stoping renew on %s" , keyName )
265
+ return
266
+ }
267
+ log .Infof ("RenewPeriodic for session %s exited with error: %v. Retrying.." , keyName , err )
268
+ }
269
+ }
258
270
259
271
// getServiceInstances gets the current list of service instances
260
272
func (cp * ConsulClient ) getServiceInstances (key string , waitIdx uint64 ) ([]ServiceInfo , uint64 , error ) {
0 commit comments