fix router panic (#1254)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
		| @@ -368,9 +368,11 @@ func (r *router) advertiseEvents() error { | |||||||
| 					time.Sleep(time.Second) | 					time.Sleep(time.Second) | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
| 				// reset | 				if w != nil { | ||||||
| 				w.Stop() | 					// reset | ||||||
| 				w = nil | 					w.Stop() | ||||||
|  | 					w = nil | ||||||
|  | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	}() | 	}() | ||||||
| @@ -467,7 +469,9 @@ func (r *router) advertiseEvents() error { | |||||||
| 			a.penalty += Penalty | 			a.penalty += Penalty | ||||||
| 			log.Debugf("Router advert %d for route %s %s event penalty: %f", hash, a.event.Route.Service, a.event.Route.Address, a.penalty) | 			log.Debugf("Router advert %d for route %s %s event penalty: %f", hash, a.event.Route.Service, a.event.Route.Address, a.penalty) | ||||||
| 		case <-r.exit: | 		case <-r.exit: | ||||||
| 			w.Stop() | 			if w != nil { | ||||||
|  | 				w.Stop() | ||||||
|  | 			} | ||||||
| 			return nil | 			return nil | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| @@ -700,16 +704,15 @@ func (r *router) Stop() error { | |||||||
| 		// extract the events | 		// extract the events | ||||||
| 		r.drain() | 		r.drain() | ||||||
|  |  | ||||||
|  | 		r.sub.Lock() | ||||||
| 		// close advert subscribers | 		// close advert subscribers | ||||||
| 		for id, sub := range r.subscribers { | 		for id, sub := range r.subscribers { | ||||||
| 			// close the channel | 			// close the channel | ||||||
| 			close(sub) | 			close(sub) | ||||||
|  |  | ||||||
| 			// delete the subscriber | 			// delete the subscriber | ||||||
| 			r.sub.Lock() |  | ||||||
| 			delete(r.subscribers, id) | 			delete(r.subscribers, id) | ||||||
| 			r.sub.Unlock() |  | ||||||
| 		} | 		} | ||||||
|  | 		r.sub.Unlock() | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// remove event chan | 	// remove event chan | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user