Open
Description
Describe the change
Problem:
When multiple runspaces concurrently call functions utilizing Invoke-GitHubAPI
, there's a risk of triggering multiple simultaneous refresh attempts of the same context's GitHub access token. This concurrency leads to race conditions, redundant token refreshes, and potential conflicts or errors.
Desired Behavior:
Only a single refresh operation per context should occur at a time. Subsequent calls needing the refreshed token should wait until the ongoing refresh completes, ensuring consistency and preventing conflicts.
Proposed Solution:
Implement synchronization using the System.Threading.Mutex
class:
- When a context initiates a token refresh, it creates and acquires a mutex lock specific to that context.
- Other parallel runspaces attempting to refresh the same context should detect the mutex lock and wait until it's released.
- Upon successful token refresh, release and remove the mutex.
- Any waiting processes will then reload the updated context without attempting another redundant refresh.
Implementation Considerations:
- Ensure mutex names are unique per context.
- Use proper
try
/finally
blocks to guarantee mutex release. - Dispose of mutex objects appropriately after use.
This solution will eliminate concurrent token refresh attempts and enhance stability and reliability for parallelized GitHub API calls.
Metadata
Metadata
Assignees
Type
Projects
Status
Todo