|
61 | 61 | // control number of concurrent created (but not closed) handshakes. |
62 | 62 | clientHandshakes = semaphore.NewWeighted(int64(envconfig.ALTSMaxConcurrentHandshakes)) |
63 | 63 | 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") |
64 | 66 | // errOutOfBound occurs when the handshake service returns a consumed |
65 | 67 | // bytes value larger than the buffer that was passed to it originally. |
66 | 68 | 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, |
154 | 156 | // ClientHandshake starts and completes a client ALTS handshake for GCP. Once |
155 | 157 | // done, ClientHandshake returns a secure connection. |
156 | 158 | 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 |
159 | 161 | } |
160 | 162 | defer clientHandshakes.Release(1) |
161 | 163 |
|
@@ -207,8 +209,8 @@ func (h *altsHandshaker) ClientHandshake(ctx context.Context) (net.Conn, credent |
207 | 209 | // ServerHandshake starts and completes a server ALTS handshake for GCP. Once |
208 | 210 | // done, ServerHandshake returns a secure connection. |
209 | 211 | 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 |
212 | 214 | } |
213 | 215 | defer serverHandshakes.Release(1) |
214 | 216 |
|
|
0 commit comments