@@ -26,34 +26,37 @@ func (c *IOLimiterV2) Name() string { return "iolimiter-v2" }
2626func (c * IOLimiterV2 ) Type () Version { return Version2 }
2727
2828func (c * IOLimiterV2 ) Apply (ctx context.Context , basePath , cgroupPath string ) error {
29- // We are racing workspacekit and the interaction with disks.
30- // If we did this just once there's a chance we haven't interacted with all
31- // devices yet, and hence would not impose IO limits on them.
32- ticker := time .NewTicker (30 * time .Second )
33- defer ticker .Stop ()
34- for {
35- select {
36- case <- ctx .Done ():
37- // Prior to shutting down though, we need to reset the IO limits to ensure we don't have
38- // processes stuck in the uninterruptable "D" (disk sleep) state. This would prevent the
39- // workspace pod from shutting down.
40- c .WriteBytesPerSecond = 0
41- c .ReadBytesPerSecond = 0
42- c .WriteIOPs = 0
43- c .ReadIOPs = 0
29+ go func () {
30+ // We are racing workspacekit and the interaction with disks.
31+ // If we did this just once there's a chance we haven't interacted with all
32+ // devices yet, and hence would not impose IO limits on them.
33+ ticker := time .NewTicker (30 * time .Second )
34+ defer ticker .Stop ()
35+ for {
36+ select {
37+ case <- ctx .Done ():
38+ // Prior to shutting down though, we need to reset the IO limits to ensure we don't have
39+ // processes stuck in the uninterruptable "D" (disk sleep) state. This would prevent the
40+ // workspace pod from shutting down.
41+ c .WriteBytesPerSecond = 0
42+ c .ReadBytesPerSecond = 0
43+ c .WriteIOPs = 0
44+ c .ReadIOPs = 0
4445
45- err := c .writeIOMax (filepath .Join (basePath , cgroupPath ))
46- if err != nil {
47- return err
48- }
49- return ctx .Err ()
50- case <- ticker .C :
51- err := c .writeIOMax (filepath .Join (basePath , cgroupPath ))
52- if err != nil {
53- log .WithError (err ).WithField ("cgroupPath" , cgroupPath ).Error ("cannot write IO limits" )
46+ err := c .writeIOMax (filepath .Join (basePath , cgroupPath ))
47+ if err != nil {
48+ log .WithError (err ).WithField ("cgroupPath" , cgroupPath ).Error ("cannot write IO limits" )
49+ }
50+ return
51+ case <- ticker .C :
52+ err := c .writeIOMax (filepath .Join (basePath , cgroupPath ))
53+ if err != nil {
54+ log .WithError (err ).WithField ("cgroupPath" , cgroupPath ).Error ("cannot write IO limits" )
55+ }
5456 }
5557 }
56- }
58+ }()
59+ return nil
5760}
5861
5962func (c * IOLimiterV2 ) writeIOMax (loc string ) error {
0 commit comments