volume/flocker: plug time.Ticker resource leak
This commit ensures that `flockerMounter.updateDatasetPrimary` does not leak running `time.Ticker` instances. Upon termination of the consuming routine, we stop the tickers.
This commit is contained in:
		@@ -223,8 +223,10 @@ func (b flockerMounter) updateDatasetPrimary(datasetID, primaryUUID string) erro
 | 
				
			|||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	timeoutChan := time.NewTimer(timeoutWaitingForVolume).C
 | 
						timeoutChan := time.NewTimer(timeoutWaitingForVolume)
 | 
				
			||||||
	tickChan := time.NewTicker(tickerWaitingForVolume).C
 | 
						defer timeoutChan.Stop()
 | 
				
			||||||
 | 
						tickChan := time.NewTicker(tickerWaitingForVolume)
 | 
				
			||||||
 | 
						defer tickChan.Stop()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for {
 | 
						for {
 | 
				
			||||||
		if s, err := b.client.GetDatasetState(datasetID); err == nil && s.Primary == primaryUUID {
 | 
							if s, err := b.client.GetDatasetState(datasetID); err == nil && s.Primary == primaryUUID {
 | 
				
			||||||
@@ -232,12 +234,12 @@ func (b flockerMounter) updateDatasetPrimary(datasetID, primaryUUID string) erro
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		select {
 | 
							select {
 | 
				
			||||||
		case <-timeoutChan:
 | 
							case <-timeoutChan.C:
 | 
				
			||||||
			return fmt.Errorf(
 | 
								return fmt.Errorf(
 | 
				
			||||||
				"Timed out waiting for the dataset_id: '%s' to be moved to the primary: '%s'\n%v",
 | 
									"Timed out waiting for the dataset_id: '%s' to be moved to the primary: '%s'\n%v",
 | 
				
			||||||
				datasetID, primaryUUID, err,
 | 
									datasetID, primaryUUID, err,
 | 
				
			||||||
			)
 | 
								)
 | 
				
			||||||
		case <-tickChan:
 | 
							case <-tickChan.C:
 | 
				
			||||||
			break
 | 
								break
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user