@@ -19,7 +19,6 @@ package cacher
19
19
import (
20
20
"context"
21
21
"fmt"
22
- "math"
23
22
"net/http"
24
23
"reflect"
25
24
"sync"
@@ -365,16 +364,11 @@ func (c *Cacher) Watch(ctx context.Context, key string, resourceVersion string,
365
364
chanSize = 1000
366
365
}
367
366
368
- // Determine watch timeout
369
- timeout := time .Duration (math .MaxInt64 )
370
- if deadline , ok := ctx .Deadline (); ok {
371
- timeout = deadline .Sub (time .Now ())
372
- }
373
367
// Create a watcher here to reduce memory allocations under lock,
374
368
// given that memory allocation may trigger GC and block the thread.
375
369
// Also note that emptyFunc is a placeholder, until we will be able
376
370
// to compute watcher.forget function (which has to happen under lock).
377
- watcher := newCacheWatcher (chanSize , filterWithAttrsFunction (key , pred ), emptyFunc , c .versioner , timeout )
371
+ watcher := newCacheWatcher (chanSize , filterWithAttrsFunction (key , pred ), emptyFunc , c .versioner )
378
372
379
373
// We explicitly use thread unsafe version and do locking ourself to ensure that
380
374
// no new events will be processed in the meantime. The watchCache will be unlocked
@@ -407,7 +401,7 @@ func (c *Cacher) Watch(ctx context.Context, key string, resourceVersion string,
407
401
c .watcherIdx ++
408
402
}()
409
403
410
- go watcher .process (ctx , initEvents , watchRV )
404
+ go watcher .process (initEvents , watchRV )
411
405
return watcher , nil
412
406
}
413
407
@@ -894,34 +888,9 @@ type cacheWatcher struct {
894
888
stopped bool
895
889
forget func ()
896
890
versioner storage.Versioner
897
- timer * time.Timer
898
- }
899
-
900
- var timerPool sync.Pool
901
-
902
- func newTimer (d time.Duration ) * time.Timer {
903
- t , ok := timerPool .Get ().(* time.Timer )
904
- if ok {
905
- t .Reset (d )
906
- } else {
907
- t = time .NewTimer (d )
908
- }
909
- return t
910
891
}
911
892
912
- func freeTimer (timer * time.Timer ) {
913
- if ! timer .Stop () {
914
- // Consume triggered (but not yet received) timer event
915
- // so that future reuse does not get a spurious timeout.
916
- select {
917
- case <- timer .C :
918
- default :
919
- }
920
- }
921
- timerPool .Put (timer )
922
- }
923
-
924
- func newCacheWatcher (chanSize int , filter filterWithAttrsFunc , forget func (), versioner storage.Versioner , timeout time.Duration ) * cacheWatcher {
893
+ func newCacheWatcher (chanSize int , filter filterWithAttrsFunc , forget func (), versioner storage.Versioner ) * cacheWatcher {
925
894
return & cacheWatcher {
926
895
input : make (chan * watchCacheEvent , chanSize ),
927
896
result : make (chan watch.Event , chanSize ),
@@ -930,7 +899,6 @@ func newCacheWatcher(chanSize int, filter filterWithAttrsFunc, forget func(), ve
930
899
stopped : false ,
931
900
forget : forget ,
932
901
versioner : versioner ,
933
- timer : newTimer (timeout ),
934
902
}
935
903
}
936
904
@@ -951,7 +919,6 @@ func (c *cacheWatcher) stop() {
951
919
c .stopped = true
952
920
close (c .done )
953
921
close (c .input )
954
- freeTimer (c .timer )
955
922
}
956
923
}
957
924
@@ -1040,7 +1007,7 @@ func (c *cacheWatcher) sendWatchCacheEvent(event *watchCacheEvent) {
1040
1007
}
1041
1008
}
1042
1009
1043
- func (c * cacheWatcher ) process (ctx context. Context , initEvents []* watchCacheEvent , resourceVersion uint64 ) {
1010
+ func (c * cacheWatcher ) process (initEvents []* watchCacheEvent , resourceVersion uint64 ) {
1044
1011
defer utilruntime .HandleCrash ()
1045
1012
1046
1013
// Check how long we are processing initEvents.
@@ -1076,20 +1043,10 @@ func (c *cacheWatcher) process(ctx context.Context, initEvents []*watchCacheEven
1076
1043
1077
1044
defer close (c .result )
1078
1045
defer c .Stop ()
1079
- for {
1080
- select {
1081
- case event , ok := <- c .input :
1082
- if ! ok {
1083
- return
1084
- }
1085
- // only send events newer than resourceVersion
1086
- if event .ResourceVersion > resourceVersion {
1087
- c .sendWatchCacheEvent (event )
1088
- }
1089
- case <- ctx .Done ():
1090
- return
1091
- case <- c .timer .C :
1092
- return
1046
+ for event := range c .input {
1047
+ // only send events newer than resourceVersion
1048
+ if event .ResourceVersion > resourceVersion {
1049
+ c .sendWatchCacheEvent (event )
1093
1050
}
1094
1051
}
1095
1052
}
0 commit comments