Fixing intermittent pubsub test failures by garrettjonesgoogle · Pull Request #1756 · googleapis/google-cloud-java · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,31 @@
package com.google.cloud.pubsub.spi.v1;

import io.grpc.Status;
import io.grpc.StatusRuntimeException;

/** Utilities for handling gRPC {@link Status}. */
final class StatusUtil {
private StatusUtil() {
// Static class, not instatiable.
// Static class, not instantiable.
}

public static boolean isRetryable(Status status) {
switch (status.getCode()) {
public static boolean isRetryable(Throwable error) {
if (!(error instanceof StatusRuntimeException)) {
return true;
}
StatusRuntimeException statusRuntimeException = (StatusRuntimeException) error;
switch (statusRuntimeException.getStatus().getCode()) {
case DEADLINE_EXCEEDED:
case INTERNAL:
case CANCELLED:
case RESOURCE_EXHAUSTED:
case UNAVAILABLE:
return true;
case UNAVAILABLE:
if (statusRuntimeException.getMessage().contains("Server shutdownNow invoked")) {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

return false;
} else {
return true;
}
default:
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package com.google.cloud.pubsub.spi.v1;

import static com.google.cloud.pubsub.spi.v1.StatusUtil.isRetryable;

import com.google.api.gax.core.FlowController;
import com.google.api.stats.Distribution;
import com.google.auth.Credentials;
Expand Down Expand Up @@ -179,9 +177,13 @@ public void onSuccess(@Nullable Void result) {
}

@Override
public void onFailure(Throwable t) {
Status errorStatus = Status.fromThrowable(t);
if (isRetryable(errorStatus) && isAlive()) {
public void onFailure(Throwable cause) {
if (!isAlive()) {
// we don't care about subscription failures when we're no longer running.
logger.log(Level.FINE, "pull failure after service no longer running", cause);
return;
}
if (StatusUtil.isRetryable(cause)) {
long backoffMillis = channelReconnectBackoff.getMillis();
channelReconnectBackoff = channelReconnectBackoff.plus(backoffMillis);
executor.schedule(
Expand All @@ -194,9 +196,7 @@ public void run() {
backoffMillis,
TimeUnit.MILLISECONDS);
} else {
if (isAlive()) {
notifyFailed(t);
}
notifyFailed(cause);
}
}
},
Expand Down