In the event watchRegistry or watchTable exit then close the go routines
This commit is contained in:
		| @@ -177,10 +177,24 @@ func (r *router) watchRegistry(w registry.Watcher) error { | |||||||
| 	// wait in the background for the router to stop | 	// wait in the background for the router to stop | ||||||
| 	// when the router stops, stop the watcher and exit | 	// when the router stops, stop the watcher and exit | ||||||
| 	r.wg.Add(1) | 	r.wg.Add(1) | ||||||
|  |  | ||||||
|  | 	exit := make(chan bool) | ||||||
|  |  | ||||||
|  | 	defer func() { | ||||||
|  | 		// close the exit channel when the go routine finishes | ||||||
|  | 		close(exit) | ||||||
|  | 		r.wg.Done() | ||||||
|  | 	}() | ||||||
|  |  | ||||||
| 	go func() { | 	go func() { | ||||||
| 		defer r.wg.Done() | 		defer w.Stop() | ||||||
| 		<-r.exit |  | ||||||
| 		w.Stop() | 		select { | ||||||
|  | 		case <-r.exit: | ||||||
|  | 			return | ||||||
|  | 		case <-exit: | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
| 	}() | 	}() | ||||||
|  |  | ||||||
| 	var watchErr error | 	var watchErr error | ||||||
| @@ -208,10 +222,23 @@ func (r *router) watchTable(w Watcher) error { | |||||||
| 	// wait in the background for the router to stop | 	// wait in the background for the router to stop | ||||||
| 	// when the router stops, stop the watcher and exit | 	// when the router stops, stop the watcher and exit | ||||||
| 	r.wg.Add(1) | 	r.wg.Add(1) | ||||||
|  | 	exit := make(chan bool) | ||||||
|  |  | ||||||
|  | 	defer func() { | ||||||
|  | 		// close the exit channel when the go routine finishes | ||||||
|  | 		close(exit) | ||||||
|  | 		r.wg.Done() | ||||||
|  | 	}() | ||||||
|  |  | ||||||
| 	go func() { | 	go func() { | ||||||
| 		defer r.wg.Done() | 		defer w.Stop() | ||||||
| 		<-r.exit |  | ||||||
| 		w.Stop() | 		select { | ||||||
|  | 		case <-r.exit: | ||||||
|  | 			return | ||||||
|  | 		case <-exit: | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
| 	}() | 	}() | ||||||
|  |  | ||||||
| 	var watchErr error | 	var watchErr error | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user