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.
17
17
package metrics
18
18
19
19
import (
20
+ "context"
20
21
"net/http"
21
22
"sync"
22
23
"time"
@@ -290,16 +291,25 @@ func (opMgr *operationMetricsManager) init() {
290
291
// While we always maintain the number of operations in flight
291
292
// for every metrics operation start/finish, if any are leaked,
292
293
// 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 )
294
297
}
295
298
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
+ }
303
313
}
304
314
}
305
315
You can’t perform that action at this time.
0 commit comments