Revert "alts: Queue ALTS handshakes once limit is reached rather than dropping. (#6884)" (#6903)

This reverts commit adc76852e0.
This commit is contained in:
Matthew Stevenson 2023-12-28 14:33:59 -08:00 committed by GitHub
parent 4f03f3ff32
commit 71cc0f1675
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 11 deletions

View File

@ -397,7 +397,7 @@ func establishAltsConnection(t *testing.T, handshakerAddress, serverAddress stri
if err == nil { if err == nil {
break break
} }
if code := status.Code(err); code == codes.Unavailable || code == codes.DeadlineExceeded { if code := status.Code(err); code == codes.Unavailable {
// The server is not ready yet. Try again. // The server is not ready yet. Try again.
continue continue
} }

View File

@ -61,6 +61,8 @@ var (
// control number of concurrent created (but not closed) handshakes. // control number of concurrent created (but not closed) handshakes.
clientHandshakes = semaphore.NewWeighted(int64(envconfig.ALTSMaxConcurrentHandshakes)) clientHandshakes = semaphore.NewWeighted(int64(envconfig.ALTSMaxConcurrentHandshakes))
serverHandshakes = semaphore.NewWeighted(int64(envconfig.ALTSMaxConcurrentHandshakes)) serverHandshakes = semaphore.NewWeighted(int64(envconfig.ALTSMaxConcurrentHandshakes))
// errDropped occurs when maxPendingHandshakes is reached.
errDropped = errors.New("maximum number of concurrent ALTS handshakes is reached")
// errOutOfBound occurs when the handshake service returns a consumed // errOutOfBound occurs when the handshake service returns a consumed
// bytes value larger than the buffer that was passed to it originally. // bytes value larger than the buffer that was passed to it originally.
errOutOfBound = errors.New("handshaker service consumed bytes value is out-of-bound") 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,
// ClientHandshake starts and completes a client ALTS handshake for GCP. Once // ClientHandshake starts and completes a client ALTS handshake for GCP. Once
// done, ClientHandshake returns a secure connection. // done, ClientHandshake returns a secure connection.
func (h *altsHandshaker) ClientHandshake(ctx context.Context) (net.Conn, credentials.AuthInfo, error) { func (h *altsHandshaker) ClientHandshake(ctx context.Context) (net.Conn, credentials.AuthInfo, error) {
if err := clientHandshakes.Acquire(ctx, 1); err != nil { if !clientHandshakes.TryAcquire(1) {
return nil, nil, err return nil, nil, errDropped
} }
defer clientHandshakes.Release(1) defer clientHandshakes.Release(1)
@ -207,8 +209,8 @@ func (h *altsHandshaker) ClientHandshake(ctx context.Context) (net.Conn, credent
// ServerHandshake starts and completes a server ALTS handshake for GCP. Once // ServerHandshake starts and completes a server ALTS handshake for GCP. Once
// done, ServerHandshake returns a secure connection. // done, ServerHandshake returns a secure connection.
func (h *altsHandshaker) ServerHandshake(ctx context.Context) (net.Conn, credentials.AuthInfo, error) { func (h *altsHandshaker) ServerHandshake(ctx context.Context) (net.Conn, credentials.AuthInfo, error) {
if err := serverHandshakes.Acquire(ctx, 1); err != nil { if !serverHandshakes.TryAcquire(1) {
return nil, nil, err return nil, nil, errDropped
} }
defer serverHandshakes.Release(1) defer serverHandshakes.Release(1)

View File

@ -193,10 +193,10 @@ func (s) TestClientHandshake(t *testing.T) {
}() }()
} }
// Ensure that there are no errors. // Ensure all errors are expected.
for i := 0; i < testCase.numberOfHandshakes; i++ { for i := 0; i < testCase.numberOfHandshakes; i++ {
if err := <-errc; err != nil { if err := <-errc; err != nil && err != errDropped {
t.Errorf("ClientHandshake() = _, %v, want _, <nil>", err) t.Errorf("ClientHandshake() = _, %v, want _, <nil> or %v", err, errDropped)
} }
} }
@ -250,10 +250,10 @@ func (s) TestServerHandshake(t *testing.T) {
}() }()
} }
// Ensure that there are no errors. // Ensure all errors are expected.
for i := 0; i < testCase.numberOfHandshakes; i++ { for i := 0; i < testCase.numberOfHandshakes; i++ {
if err := <-errc; err != nil { if err := <-errc; err != nil && err != errDropped {
t.Errorf("ServerHandshake() = _, %v, want _, <nil>", err) t.Errorf("ServerHandshake() = _, %v, want _, <nil> or %v", err, errDropped)
} }
} }