From a89f1b7cca91d59f10daf5a59f5e72be54029454 Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Fri, 14 Oct 2022 19:23:57 +0200 Subject: [PATCH] Use ErrEventOverflow instead of "short read in readEvents()" Fixes #383 --- backend_fen.go | 6 ++++++ backend_inotify.go | 6 ++++++ backend_kqueue.go | 6 ++++++ backend_windows.go | 8 +++++++- fsnotify.go | 5 +++-- mkdoc.zsh | 6 ++++++ 6 files changed, 34 insertions(+), 3 deletions(-) diff --git a/backend_fen.go b/backend_fen.go index f7f2de9f..515dd671 100644 --- a/backend_fen.go +++ b/backend_fen.go @@ -110,6 +110,12 @@ type Watcher struct { Events chan Event // Errors sends any errors. + // + // [ErrEventOverflow] is used to indicate ther are too many events: + // + // - inotify: there are too many queued events (fs.inotify.max_queued_events sysctl) + // - windows: The buffer size is too small; [WithBufferSize] can be used to increase it. + // - kqueue, fen: not used. Errors chan error mu sync.Mutex diff --git a/backend_inotify.go b/backend_inotify.go index 9b591137..701e5258 100644 --- a/backend_inotify.go +++ b/backend_inotify.go @@ -113,6 +113,12 @@ type Watcher struct { Events chan Event // Errors sends any errors. + // + // [ErrEventOverflow] is used to indicate ther are too many events: + // + // - inotify: there are too many queued events (fs.inotify.max_queued_events sysctl) + // - windows: The buffer size is too small; [WithBufferSize] can be used to increase it. + // - kqueue, fen: not used. Errors chan error // Store fd here as os.File.Read() will no longer return on close after diff --git a/backend_kqueue.go b/backend_kqueue.go index bcc6f84e..2916ebb2 100644 --- a/backend_kqueue.go +++ b/backend_kqueue.go @@ -111,6 +111,12 @@ type Watcher struct { Events chan Event // Errors sends any errors. + // + // [ErrEventOverflow] is used to indicate ther are too many events: + // + // - inotify: there are too many queued events (fs.inotify.max_queued_events sysctl) + // - windows: The buffer size is too small; [WithBufferSize] can be used to increase it. + // - kqueue, fen: not used. Errors chan error done chan struct{} diff --git a/backend_windows.go b/backend_windows.go index 0334f512..10799d51 100644 --- a/backend_windows.go +++ b/backend_windows.go @@ -114,6 +114,12 @@ type Watcher struct { Events chan Event // Errors sends any errors. + // + // [ErrEventOverflow] is used to indicate ther are too many events: + // + // - inotify: there are too many queued events (fs.inotify.max_queued_events sysctl) + // - windows: The buffer size is too small; [WithBufferSize] can be used to increase it. + // - kqueue, fen: not used. Errors chan error port windows.Handle // Handle to completion port @@ -665,7 +671,7 @@ func (w *Watcher) readEvents() { var offset uint32 for { if n == 0 { - w.sendError(errors.New("short read in readEvents()")) + w.sendError(ErrEventOverflow) break } diff --git a/fsnotify.go b/fsnotify.go index 8b9d53cc..6a913fc5 100644 --- a/fsnotify.go +++ b/fsnotify.go @@ -40,8 +40,8 @@ const ( // Common errors that can be reported by a watcher var ( ErrNonExistentWatch = errors.New("fsnotify: can't remove non-existent watcher") - ErrEventOverflow = errors.New("fsnotify: queue overflow") ErrClosed = errors.New("fsnotify: watcher already closed") + ErrEventOverflow = errors.New("fsnotify: queue or buffer overflow") ) func (o Op) String() string { @@ -101,7 +101,8 @@ func getOptions(opts ...addOpt) withOpts { // for other backends. // // The default value is 64K (65536 bytes) which should be enough for most -// applications, but you can increase it if you're hitting "short read" errors. +// applications, but you can increase it if you're hitting "queue or buffer +// overflow" errors ([ErrEventOverflow]). func WithBufferSize(bytes int) addOpt { return func(opt *withOpts) { opt.bufsize = bytes } } diff --git a/mkdoc.zsh b/mkdoc.zsh index 699bb998..6351713b 100755 --- a/mkdoc.zsh +++ b/mkdoc.zsh @@ -184,6 +184,12 @@ EOF errors=$(<