File tree Expand file tree Collapse file tree 1 file changed +18
-8
lines changed Expand file tree Collapse file tree 1 file changed +18
-8
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ limitations under the License.
1717package metrics
1818
1919import (
20+ "context"
2021 "net/http"
2122 "sync"
2223 "time"
@@ -290,16 +291,25 @@ func (opMgr *operationMetricsManager) init() {
290291 // While we always maintain the number of operations in flight
291292 // for every metrics operation start/finish, if any are leaked,
292293 // this scheduled routine will catch any leaked operations.
293- go opMgr .scheduleOpsInFlightMetric ()
294+ ctx , cancel := context .WithCancel (context .Background ())
295+ defer cancel ()
296+ go opMgr .scheduleOpsInFlightMetric (ctx )
294297}
295298
296- func (opMgr * operationMetricsManager ) scheduleOpsInFlightMetric () {
297- for range time .Tick (inFlightCheckInterval ) {
298- func () {
299- opMgr .mu .Lock ()
300- defer opMgr .mu .Unlock ()
301- opMgr .opInFlight .Set (float64 (len (opMgr .cache )))
302- }()
299+ func (opMgr * operationMetricsManager ) scheduleOpsInFlightMetric (ctx context.Context ) {
300+ for {
301+ select {
302+ case <- ctx .Done ():
303+ return
304+ default :
305+ for range time .NewTicker (inFlightCheckInterval ).C {
306+ func () {
307+ opMgr .mu .Lock ()
308+ defer opMgr .mu .Unlock ()
309+ opMgr .opInFlight .Set (float64 (len (opMgr .cache )))
310+ }()
311+ }
312+ }
303313 }
304314}
305315
You can’t perform that action at this time.
0 commit comments