Skip to content

[csharp][generichost] Token provider threading issue #23263

@devhl-labs

Description

@devhl-labs

P2: IsRateLimited reads _nextAvailable without synchronization while BeginRateLimit writes it under a lock. The timer thread can observe stale state and raise TokenBecameAvailable early. Guard the read with the same lock (or use a volatile/interlocked read).

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Client/TokenBase.cs, line 67:

<comment>IsRateLimited reads _nextAvailable without synchronization while BeginRateLimit writes it under a lock. The timer thread can observe stale state and raise TokenBecameAvailable early. Guard the read with the same lock (or use a volatile/interlocked read).</comment>

<file context>
@@ -0,0 +1,85 @@
+        /// <summary>
+        /// Returns true while the token is rate limited.
+        /// </summary>
+        public bool IsRateLimited => _nextAvailable > DateTime.UtcNow;
+
+        /// <summary>
</file context>
Fix with Cubic

Originally posted by @cubic-dev-ai[bot] in #23260 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions