Update Stats to use atomic operations#54
Merged
mateeullahmalik merged 1 commit intomasterfrom May 14, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR addresses a race condition occurring during concurrent ALTS handshake tests by introducing mutex protection in SecureKeyExchange and converting Stats to use atomic primitives for thread safety.
- Introduced atomic operations for call counting and tracking maximum concurrent calls in Stats.
- Updated test assertions to call the new MaxConcurrentCalls() method.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/net/credentials/alts/testutil/testutil.go | Replaced mutex with atomic operations for improved concurrency safety in Stats. |
| pkg/net/credentials/alts/handshake/handshake_test.go | Updated test assertions to utilize the new MaxConcurrentCalls() method. |
akobrin1
requested changes
May 12, 2025
Contributor
akobrin1
left a comment
There was a problem hiding this comment.
we can change implementation of Stats to atomic, but we still need Update method to return cleanup function - to correctly analyze that all handshake calls were completed.
e78afb9 to
c6e648e
Compare
akobrin1
approved these changes
May 13, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
The
TestHandshakerConcurrentHandshakestest fails with a race condition when testing with maximum concurrent handshakes:Changes
inttoint32to support atomic operationsGetMaxConcurrentCalls()accessor method for safe value retrievalThe update preserves the original API contract where
Update()still returns a cleanup function that decrements the call count when invoked. These changes should reduce overhead in high-concurrency scenarios.