Skip to content
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

Possible locking issues in PollingWildCardChangeToken? #103997

Closed
omajid opened this issue Jun 25, 2024 · 2 comments · Fixed by #104969
Closed

Possible locking issues in PollingWildCardChangeToken? #103997

omajid opened this issue Jun 25, 2024 · 2 comments · Fixed by #104969
Assignees
Milestone

Comments

@omajid
Copy link
Member

omajid commented Jun 25, 2024

public bool HasChanged
{
get
{
if (_changed)
{
return _changed;
}
if (Clock.UtcNow - _lastScanTimeUtc >= PollingInterval)
{
lock (_enumerationLock)
{
_changed = CalculateChanges();
}
}
return _changed;
}
}

This code checks _changed but not under locks. It doesn't double-check it either. It seems like this race might be possible:

  1. Thread 1 and 2 enter this method
  2. Thread 1 sees _changed is false
  3. Thread 2 sees _changed is false
  4. Thread 1 obtains lock, and scans files and updates _previousHash and sets _changed = true
  5. Thread 2 obtains lock, scans files, comparing the just-updated-by-Thread-1 value of _previousHash with the new hash value, and concludes _changed is false.
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jun 25, 2024
Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-extensions-filesystem
See info in area-owners.md if you want to be subscribed.

@adamsitnik adamsitnik removed the untriaged New issue has not been triaged by the area owner label Jul 16, 2024
@adamsitnik adamsitnik self-assigned this Jul 16, 2024
@adamsitnik adamsitnik added this to the 9.0.0 milestone Jul 16, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Aug 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants