feat: regenerate module for networksecurity#13311
Conversation
|
PiperOrigin-RevId: 919268561 |
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to refresh transport channels upon encountering an UnauthenticatedException when running in a specific environment (isMwlidEnvironment), along with rate-limiting for channel pool refreshes. Feedback on the changes highlights a critical bug in GrpcCallContext where a renamed parameter was not updated, leading to a potential NullPointerException. Additionally, the rate-limiting logic in ChannelPool could fail if System.nanoTime() returns a negative value, and querying the environment variable on every retry check in ApiResultRetryAlgorithm should be cached to avoid performance overhead.
| transportChannel.isDirectPath(), | ||
| inputChannel); |
There was a problem hiding this comment.
There is a critical bug here due to the parameter renaming. The parameter was renamed from transportChannel to inputChannel, but transportChannel.isDirectPath() was not updated to inputChannel.isDirectPath().
As a result:
transportChannelnow refers to the instance fieldthis.transportChannel, which isnullby default, leading to aNullPointerExceptionwhenwithTransportChannelis called.- Even if
this.transportChannelis not null, it incorrectly uses theisDirectPathproperty of the old channel instead of the newinputChannel.
It should be updated to inputChannel.isDirectPath().
| transportChannel.isDirectPath(), | |
| inputChannel); | |
| inputChannel.isDirectPath(), | |
| inputChannel); |
| long now = System.nanoTime(); | ||
| if (now - lastRefreshTimeNanos < TimeUnit.SECONDS.toNanos(5)) { | ||
| LOG.fine("Channel pool was refreshed recently, skipping duplicate refresh"); | ||
| return; | ||
| } | ||
| lastRefreshTimeNanos = now; |
There was a problem hiding this comment.
Since System.nanoTime() can return negative values (as its origin is arbitrary), initializing lastRefreshTimeNanos to 0 can cause the first refresh (and all subsequent refreshes until System.nanoTime() becomes positive) to be skipped. This is because now - 0 will be negative, which is always less than TimeUnit.SECONDS.toNanos(5).
To fix this, you can treat 0 as a sentinel value indicating that no refresh has occurred yet.
| long now = System.nanoTime(); | |
| if (now - lastRefreshTimeNanos < TimeUnit.SECONDS.toNanos(5)) { | |
| LOG.fine("Channel pool was refreshed recently, skipping duplicate refresh"); | |
| return; | |
| } | |
| lastRefreshTimeNanos = now; | |
| long now = System.nanoTime(); | |
| if (lastRefreshTimeNanos != 0 && now - lastRefreshTimeNanos < TimeUnit.SECONDS.toNanos(5)) { | |
| LOG.fine("Channel pool was refreshed recently, skipping duplicate refresh"); | |
| return; | |
| } | |
| lastRefreshTimeNanos = now == 0 ? 1 : now; |
| /** Returns true if previousThrowable is an {@link ApiException} that is retryable. */ | ||
| @Override | ||
| public boolean shouldRetry(Throwable previousThrowable, ResponseT previousResponse) { | ||
| if ("true".equalsIgnoreCase(System.getenv("isMwlidEnvironment")) |
There was a problem hiding this comment.
fb34b2d to
4e0c744
Compare
Command used:
python3 generation/new_client_hermetic_build/add-new-client-config.py add-new-library
--api-shortname="networksecurity"
--name-pretty="Network Security API"
--proto-path="google/cloud/networksecurity/v1"
--product-docs="https://cloud.google.com/products/networking"
--api-description="The Network Security API provides resources for configuring and managing network security."
--googleapis-committish="29c6482ccb75b302c33665d8c7d7a38d3698be53"
--library-name="network-security"
--release-level="stable"