Skip to content

Commit ca8ce66

Browse files
Revert "alts: Queue ALTS handshakes once limit is reached rather than dropping. (#6884)"
This reverts commit adc7685.
1 parent 4f03f3f commit ca8ce66

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

credentials/alts/alts_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ func establishAltsConnection(t *testing.T, handshakerAddress, serverAddress stri
397397
if err == nil {
398398
break
399399
}
400-
if code := status.Code(err); code == codes.Unavailable || code == codes.DeadlineExceeded {
400+
if code := status.Code(err); code == codes.Unavailable {
401401
// The server is not ready yet. Try again.
402402
continue
403403
}

credentials/alts/internal/handshaker/handshaker.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ var (
6161
// control number of concurrent created (but not closed) handshakes.
6262
clientHandshakes = semaphore.NewWeighted(int64(envconfig.ALTSMaxConcurrentHandshakes))
6363
serverHandshakes = semaphore.NewWeighted(int64(envconfig.ALTSMaxConcurrentHandshakes))
64+
// errDropped occurs when maxPendingHandshakes is reached.
65+
errDropped = errors.New("maximum number of concurrent ALTS handshakes is reached")
6466
// errOutOfBound occurs when the handshake service returns a consumed
6567
// bytes value larger than the buffer that was passed to it originally.
6668
errOutOfBound = errors.New("handshaker service consumed bytes value is out-of-bound")
@@ -154,8 +156,8 @@ func NewServerHandshaker(ctx context.Context, conn *grpc.ClientConn, c net.Conn,
154156
// ClientHandshake starts and completes a client ALTS handshake for GCP. Once
155157
// done, ClientHandshake returns a secure connection.
156158
func (h *altsHandshaker) ClientHandshake(ctx context.Context) (net.Conn, credentials.AuthInfo, error) {
157-
if err := clientHandshakes.Acquire(ctx, 1); err != nil {
158-
return nil, nil, err
159+
if !clientHandshakes.TryAcquire(1) {
160+
return nil, nil, errDropped
159161
}
160162
defer clientHandshakes.Release(1)
161163

@@ -207,8 +209,8 @@ func (h *altsHandshaker) ClientHandshake(ctx context.Context) (net.Conn, credent
207209
// ServerHandshake starts and completes a server ALTS handshake for GCP. Once
208210
// done, ServerHandshake returns a secure connection.
209211
func (h *altsHandshaker) ServerHandshake(ctx context.Context) (net.Conn, credentials.AuthInfo, error) {
210-
if err := serverHandshakes.Acquire(ctx, 1); err != nil {
211-
return nil, nil, err
212+
if !serverHandshakes.TryAcquire(1) {
213+
return nil, nil, errDropped
212214
}
213215
defer serverHandshakes.Release(1)
214216

credentials/alts/internal/handshaker/handshaker_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,10 @@ func (s) TestClientHandshake(t *testing.T) {
193193
}()
194194
}
195195

196-
// Ensure that there are no errors.
196+
// Ensure all errors are expected.
197197
for i := 0; i < testCase.numberOfHandshakes; i++ {
198-
if err := <-errc; err != nil {
199-
t.Errorf("ClientHandshake() = _, %v, want _, <nil>", err)
198+
if err := <-errc; err != nil && err != errDropped {
199+
t.Errorf("ClientHandshake() = _, %v, want _, <nil> or %v", err, errDropped)
200200
}
201201
}
202202

@@ -250,10 +250,10 @@ func (s) TestServerHandshake(t *testing.T) {
250250
}()
251251
}
252252

253-
// Ensure that there are no errors.
253+
// Ensure all errors are expected.
254254
for i := 0; i < testCase.numberOfHandshakes; i++ {
255-
if err := <-errc; err != nil {
256-
t.Errorf("ServerHandshake() = _, %v, want _, <nil>", err)
255+
if err := <-errc; err != nil && err != errDropped {
256+
t.Errorf("ServerHandshake() = _, %v, want _, <nil> or %v", err, errDropped)
257257
}
258258
}
259259

0 commit comments

Comments
 (0)