From 016f5877e06edfa8bd4d2a944a46c62fd0be591b Mon Sep 17 00:00:00 2001 From: Jayadeep Bejoy Date: Sat, 6 Jun 2026 22:23:32 +0530 Subject: [PATCH] =?UTF-8?q?fix:=20gRPC=20RST=5FSTREAM=20on=20event=20inges?= =?UTF-8?q?tion=20=E2=80=94=20logging=20interceptor,=20auth=20interceptor,?= =?UTF-8?q?=20envoy=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- envoy/envoy.yaml | 4 ++++ src/interceptors/auth.ts | 12 ++++++++++-- src/interceptors/logging.ts | 14 +++++++++----- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/envoy/envoy.yaml b/envoy/envoy.yaml index f3e6a1f..4b85404 100644 --- a/envoy/envoy.yaml +++ b/envoy/envoy.yaml @@ -26,10 +26,14 @@ static_resources: prefix: application/grpc route: cluster: grpc_backend + timeout: 60s + max_stream_duration: + max_stream_duration: 300s - match: prefix: "/" route: cluster: http_backend + timeout: 60s http_filters: - name: envoy.filters.http.router typed_config: diff --git a/src/interceptors/auth.ts b/src/interceptors/auth.ts index 13135eb..076b955 100644 --- a/src/interceptors/auth.ts +++ b/src/interceptors/auth.ts @@ -243,13 +243,21 @@ export function authInterceptor( } return handler(call, callback); }) - .catch((error) => callback?.(error)); + .catch((error) => { + return callback?.({ + code: grpcStatus.UNAVAILABLE, + details: error instanceof Error ? error.message : String(error), + }); + }); } return handler(call, callback); }) .catch((error) => { - return callback?.(error); + return callback?.({ + code: grpcStatus.UNAVAILABLE, + details: error instanceof Error ? error.message : String(error), + }); }); }; } diff --git a/src/interceptors/logging.ts b/src/interceptors/logging.ts index bfb5495..b9321f2 100644 --- a/src/interceptors/logging.ts +++ b/src/interceptors/logging.ts @@ -1,5 +1,5 @@ import { status as grpcStatus } from "@grpc/grpc-js"; -import type { sendUnaryData, ServerErrorResponse } from "@grpc/grpc-js"; +import type { sendUnaryData } from "@grpc/grpc-js"; import * as Sentry from "@sentry/bun"; import { logger } from "../errors/logger"; import { @@ -72,10 +72,10 @@ export function loggingInterceptor( // Handle async handlers that might throw if (result && typeof result.then === "function") { return result.catch((error: unknown) => { - if (!builder["event"].outcome) { - const errorDetails = extractErrorDetails(error); - const statusCode = grpcStatusToHttpStatus(errorDetails.code); + const errorDetails = extractErrorDetails(error); + const statusCode = grpcStatusToHttpStatus(errorDetails.code); + if (!builder["event"].outcome) { Sentry.captureException(error, { extra: { requestId, method: url, statusCode }, }); @@ -89,7 +89,11 @@ export function loggingInterceptor( const event = builder.build(); logger.emit(event); } - throw error; + + originalCallback?.({ + code: errorDetails.code, + details: errorDetails.message, + }); }); } };