Skip to content

Fix file watcher data race #1177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2025
Merged

Fix file watcher data race #1177

merged 1 commit into from
Jun 13, 2025

Conversation

jakebailey
Copy link
Member

Fixes #1163

No need for a mutex here, a SyncSet and atomics are correct for this given watchers are increasing and unique.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a file watcher data race by replacing non-thread-safe variables with atomic types and a thread-safe set implementation.

  • Uses atomic.Uint32 for safely incrementing the watcher ID.
  • Replaces collections.Set with collections.SyncSet for managing watcher handles.
  • Introduces a new thread-safe set implementation in internal/collections/syncset.go.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
internal/lsp/server.go Updated watcher management by using atomic operations and SyncSet.
internal/collections/syncset.go New thread-safe set implementation for storing watcher handles.
Comments suppressed due to low confidence (1)

internal/lsp/server.go:199

  • [nitpick] Consider renaming the local variable 'watcherId' to 'watcherID' to maintain consistency with the struct field name.
watcherId := fmt.Sprintf("watcher-%d", s.watcherID.Add(1))

@jakebailey jakebailey added this pull request to the merge queue Jun 13, 2025
Merged via the queue into main with commit 64f9931 Jun 13, 2025
22 checks passed
@jakebailey jakebailey deleted the jabaile/file-watcher-atomics branch June 13, 2025 01:59
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.

Data race in watchedFiles update
2 participants