Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ namespace LaunchDarkly.Sdk.Client.PlatformSpecific
{
internal static partial class AsyncScheduler
{
private static volatile Task _lastScheduledTask = Task.CompletedTask;

private static void PlatformScheduleAction(Action a)
{
Task.Run(a);
// Chain the new action to run after the previous one completes
// This ensures actions run in order while maintaining fire-and-forget behavior
_lastScheduledTask = _lastScheduledTask.ContinueWith(_ => a());
Copy link

Choose a reason for hiding this comment

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

Bug: Race Condition in Task Scheduler

There's a race condition in PlatformScheduleAction. Concurrent calls can cause _lastScheduledTask to be updated non-atomically, which breaks the intended sequential ordering of scheduled tasks. This means tasks may execute out of order or in parallel, as volatile doesn't ensure atomicity for read-modify-write operations.

Fix in Cursor Fix in Web

}
}
}
Loading