Skip to content

Conversation

@bboreham
Copy link
Contributor

This detail got lost in #632.

@mweibel
Copy link

mweibel commented Feb 25, 2025

@bboreham thanks for the PR - I'm investigating a similar issue (deadlock on windows) - I have it not yet pinned down but it might be because of fsnotify, too.

However, when testing out your changes I didn't see any behavior changes. As I'm not sure yet if it's really fsnotify in our case, take my words with a grain of salt.
When going through the new code, I see however a bit of a discrepancy in how windows vs non-windows is treated and this change is not enough to fix the issue.

NewWatcher creates a unbuffered Events channel and calls newBackend:

fsnotify/fsnotify.go

Lines 251 to 253 in a9bc2e0

func NewWatcher() (*Watcher, error) {
ev, errs := make(chan Event), make(chan error)
b, err := newBackend(ev, errs)

In non-windows systems (E.g. inotify), newBackend calls newBufferedBackend with size 0:

fsnotify/backend_inotify.go

Lines 173 to 175 in a9bc2e0

func newBackend(ev chan Event, errs chan error) (backend, error) {
return newBufferedBackend(0, ev, errs)
}

In windows systems however, it calls newBufferedBackend with size 50:

func newBackend(ev chan Event, errs chan error) (backend, error) {
return newBufferedBackend(50, ev, errs)
}

So in the case of windows, when calling fsnotify.NewWatcher, it has an unbuffered Events channel, but windows calls newBufferedBackend with size 50 (even though the sz param is not used in that function).

So IMO the creation of the Events channel should not be done in NewWatcher but instead individually in newBufferedBackend.

What is your take on this?

@bboreham
Copy link
Contributor Author

It seems to me you are proposing a change to the design and/or API. I didn't spend enough time on this to make such judgements.

I was reporting #656, and found a workaround which was defeated by this simpler problem.

However in the project where fsnotify is used, we pinned to the older version 1.7.

@mweibel
Copy link

mweibel commented Feb 25, 2025

@bboreham maybe it wasn't clear what my intention was then:

  • the <=1.7 code used a buffered channel of size 50 for windows in all cases (using NewWatcher or using NewBufferedWatcher)
  • the 1.8 code uses a buffered channel only if using NewBufferedWatcher

This is because the creation of the Events channel (with/without buffer) is in the platform-agnostic fsnotify.go and only the backend creation is platform-specific.

Therefore, this fix here is valid for users using NewBufferedWatcher but doesn't fix users using NewWatcher on windows. This is a breaking change from the previous version and seems to deadlock even when merging this change.

@bboreham
Copy link
Contributor Author

doesn't fix users using NewWatcher

Agreed. I did not claim this PR fixes any issue, especially not #656.

@arp242 arp242 force-pushed the buffered branch 2 times, most recently from 44f0fa0 to 32b1aa5 Compare March 31, 2025 09:40
The size parameter didn't actually get passed to the make() call;
regression from fsnotify#632. Also make sure the default buffer size is 50 on
Windows again.

There is no need for a separate newBackend() and newBufferedBackend() in
the first place, as the buffer size just controls the channel buffer
size which is now done in the generic fsnotify.go, so refactor to remove
that.

Signed-off-by: Bryan Boreham <[email protected]>
@arp242
Copy link
Member

arp242 commented Mar 31, 2025

Thanks; I updated the PR to also a buffer size of 50 by default like before, and added a test for the lot.

@arp242 arp242 merged commit b190600 into fsnotify:main Mar 31, 2025
20 checks passed
project-mirrors-bot-tu bot pushed a commit to project-mirrors/forgejo-as-gitea-fork that referenced this pull request Apr 6, 2025
…tea#7473)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github.com/fsnotify/fsnotify](https://github.com/fsnotify/fsnotify) | require | minor | `v1.8.0` -> `v1.9.0` |

---

### Release Notes

<details>
<summary>fsnotify/fsnotify (github.com/fsnotify/fsnotify)</summary>

### [`v1.9.0`](https://github.com/fsnotify/fsnotify/releases/tag/v1.9.0)

[Compare Source](fsnotify/fsnotify@v1.8.0...v1.9.0)

##### Changes and fixes

-   all: make BufferedWatcher buffered again ([#&go-gitea#8203;657])

-   inotify: fix race when adding/removing watches while a watched path is being deleted ([#&go-gitea#8203;678], [#&go-gitea#8203;686])

-   inotify: don't send empty event if a watched path is unmounted ([#&go-gitea#8203;655])

-   inotify: don't register duplicate watches when watching both a symlink and its target; previously that would get "half-added" and removing the second would panic ([#&go-gitea#8203;679])

-   kqueue: fix watching relative symlinks ([#&go-gitea#8203;681])

-   kqueue: correctly mark pre-existing entries when watching a link to a dir on kqueue ([#&go-gitea#8203;682])

-   illumos: don't send error if changed file is deleted while processing the event ([#&go-gitea#8203;678])

[#&go-gitea#8203;657]: fsnotify/fsnotify#657

[#&go-gitea#8203;678]: fsnotify/fsnotify#678

[#&go-gitea#8203;686]: fsnotify/fsnotify#686

[#&go-gitea#8203;655]: fsnotify/fsnotify#655

[#&go-gitea#8203;681]: fsnotify/fsnotify#681

[#&go-gitea#8203;679]: fsnotify/fsnotify#679

[#&go-gitea#8203;682]: fsnotify/fsnotify#682

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "* 0-3 * * *" (UTC), Automerge - "* 0-3 * * *" (UTC).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4yMjIuMSIsInVwZGF0ZWRJblZlciI6IjM5LjIyMi4xIiwidGFyZ2V0QnJhbmNoIjoiZm9yZ2VqbyIsImxhYmVscyI6WyJkZXBlbmRlbmN5LXVwZ3JhZGUiLCJ0ZXN0L25vdC1uZWVkZWQiXX0=-->

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7473
Reviewed-by: Earl Warren <[email protected]>
Co-authored-by: Renovate Bot <[email protected]>
Co-committed-by: Renovate Bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants