dotnet / dotnet/sdk

Can SnapshottingCollection.GetSnapshot() call CreateSnapshot() multiple times?

Open
#41,663 0 comments 0 reactions 0 assignees View on GitHub
Area-Install untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

This code checks that `snapshot == null` before taking a lock, but never checks it again:

https://github.com/dotnet/sdk/blob/88ec7422ea36b15860ea29ec04cc8f8a2c60974f/src/Cli/dotnet/Telemetry/PersistenceChannel/SnapshottingCollection.cs#L79-L92

I think this sequence of events can result in multiple calls to `CreateSnapshot()`:

1. Thread 1 calls `GetSnapshot()` and see `localSnapshot = snapshot` && `localSnapshot == null`
2. Thread 2 calls `GetSnapshot()` and see `localSnapshot = snapshot` && `localSnapshot == null`
3. Thread 1 enters the lock block, and runs CreateSnapshot, and updates `snapshot`
4. Thread 2 enters the lock block, runs CreateSnapshot again, and updates `snapshot` again.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.