Skip to content

Commit 73b86d0

Browse files
committed
pkg/cdi: don't crash if we fail to create fsnotify watch.
Don't crash in update() if we fail to create an fsnotify watch. This can happen if we have too many open files. In this case we now record a failure for all configured spec directories and in update we always trigger a refresh. If the process if ever able to create new file descriptors the cache becomes functional but in a 'always implicitly fully refreshed' mode instead of auto- refreshed. It's not entirely clear what is the best option to deal with a failed watch creation. Being out of file descriptors typically results in a cascading chain of errors which the process does not usually survive. This fix aims for minimal footprint. On failed watch creation it does not render the cache fully unusable. If the process is ever able to create new file descriptors again the cache also becomes functional, but instead of autorefreshed mode it will be in an 'always implicitly fully refreshed' mode. Signed-off-by: Krisztian Litkey <[email protected]>
1 parent c0e6a8a commit 73b86d0

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pkg/cdi/cache.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,14 @@ func (w *watch) update(dirErrors map[string]error, removed ...string) bool {
579579
update bool
580580
)
581581

582+
// If we failed to create an fsnotify.Watcher we have a nil watcher here
583+
// (but with autoRefresh left on). One known case when this can happen is
584+
// if we have too many open files. In that case we always return true and
585+
// force a refresh.
586+
if w.watcher == nil {
587+
return true
588+
}
589+
582590
for dir, ok = range w.tracked {
583591
if ok {
584592
continue

0 commit comments

Comments
 (0)