Skip to content

Commit

Permalink
windows: use ErrEventOverflow instead of "short read in readEvents()" (
Browse files Browse the repository at this point in the history
…#525)

Extracted from #521; we want to do this no matter what.

Fixes #383
  • Loading branch information
arp242 committed Oct 15, 2022
1 parent 36569c7 commit c62f582
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -28,13 +28,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
up as a fsnotify.Write event. This is never useful, and could result in many
spurious Write events.

- windows: return ErrEventOverflow if the buffer is full ([#525])

Before it would merely return "short read", making it hard to detect this
error.

- all: return ErrClosed on Add() when the watcher is closed ([#516])


[#371]: https://github.com/fsnotify/fsnotify/pull/371
[#516]: https://github.com/fsnotify/fsnotify/pull/516
[#518]: https://github.com/fsnotify/fsnotify/pull/518
[#520]: https://github.com/fsnotify/fsnotify/pull/520
[#525]: https://github.com/fsnotify/fsnotify/pull/525

## [1.6.0] - 2022-10-13

Expand Down
6 changes: 6 additions & 0 deletions backend_fen.go
Expand Up @@ -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.
// - kqueue, fen: not used.
Errors chan error

mu sync.Mutex
Expand Down
6 changes: 6 additions & 0 deletions backend_inotify.go
Expand Up @@ -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.
// - kqueue, fen: not used.
Errors chan error

// Store fd here as os.File.Read() will no longer return on close after
Expand Down
6 changes: 6 additions & 0 deletions backend_kqueue.go
Expand Up @@ -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.
// - kqueue, fen: not used.
Errors chan error

done chan struct{}
Expand Down
8 changes: 7 additions & 1 deletion backend_windows.go
Expand Up @@ -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.
// - kqueue, fen: not used.
Errors chan error

port windows.Handle // Handle to completion port
Expand Down Expand Up @@ -643,7 +649,7 @@ func (w *Watcher) readEvents() {
var offset uint32
for {
if n == 0 {
w.sendError(errors.New("short read in readEvents()"))
w.sendError(ErrEventOverflow)
break
}

Expand Down
2 changes: 1 addition & 1 deletion fsnotify.go
Expand Up @@ -47,7 +47,7 @@ const (
// Common errors that can be reported.
var (
ErrNonExistentWatch = errors.New("fsnotify: can't remove non-existent watcher")
ErrEventOverflow = errors.New("fsnotify: queue overflow")
ErrEventOverflow = errors.New("fsnotify: queue or buffer overflow")
ErrClosed = errors.New("fsnotify: watcher already closed")
)

Expand Down
6 changes: 6 additions & 0 deletions mkdoc.zsh
Expand Up @@ -171,6 +171,12 @@ EOF

errors=$(<<EOF
// 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.
// - kqueue, fen: not used.
EOF
)

Expand Down

0 comments on commit c62f582

Please sign in to comment.