Skip to content

Commit b9d579b

Browse files
authored
Merge pull request #291 from weaviate/grpc/add-one-retry-to-health-check
Adds a single retry of UNAVAILABLE to health check
2 parents 27d6b26 + 85d70ee commit b9d579b

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/connection/grpc.ts

+21-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ import { InternalConnectionParams } from './http.js';
55

66
import { ConsistencyLevel } from '../data/index.js';
77

8-
import { ChannelCredentials, ChannelOptions, createChannel, createClientFactory, Metadata } from 'nice-grpc';
8+
import {
9+
ChannelCredentials,
10+
ChannelOptions,
11+
ClientError,
12+
createChannel,
13+
createClientFactory,
14+
Metadata,
15+
Status,
16+
} from 'nice-grpc';
917
import { retryMiddleware } from 'nice-grpc-client-middleware-retry';
1018

1119
import { HealthCheckResponse_ServingStatus, HealthDefinition } from '../proto/google/health/v1/health.js';
@@ -204,7 +212,18 @@ export const grpcClient = (config: GrpcConnectionParams & { grpcMaxMessageLength
204212
const controller = new AbortController();
205213
const timeoutId = setTimeout(() => controller.abort(), (config.timeout?.init || 2) * 1000);
206214
return health
207-
.check({ service: '/grpc.health.v1.Health/Check' }, { signal: controller.signal })
215+
.check(
216+
{ service: '/grpc.health.v1.Health/Check' },
217+
{
218+
signal: controller.signal,
219+
retry: true,
220+
retryMaxAttempts: 1,
221+
retryableStatuses: [Status.UNAVAILABLE],
222+
onRetryableError(error: ClientError, attempt: number, delayMs: number) {
223+
console.warn(error, `Healthcheck ${attempt} failed. Retrying in ${delayMs}ms.`);
224+
},
225+
}
226+
)
208227
.then((res) => res.status === HealthCheckResponse_ServingStatus.SERVING)
209228
.catch((err) => {
210229
if (isAbortError(err)) {

0 commit comments

Comments
 (0)