From be916566ae43603e4ced611b5601c9b5c9b01d88 Mon Sep 17 00:00:00 2001 From: natsukingly Date: Sat, 4 Apr 2026 16:08:43 +0900 Subject: [PATCH] =?UTF-8?q?429=E3=83=AC=E3=82=B9=E3=83=9D=E3=83=B3?= =?UTF-8?q?=E3=82=B9=E3=81=AE=20Retry-After=20=E3=83=98=E3=83=83=E3=83=80?= =?UTF-8?q?=E3=83=BC=E3=81=AB=E5=AF=BE=E5=BF=9C=E3=81=97=E3=81=9F=E3=83=AA?= =?UTF-8?q?=E3=83=88=E3=83=A9=E3=82=A4=E5=87=A6=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/src/http/httpFacilitatorClient.ts | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/typescript/packages/core/src/http/httpFacilitatorClient.ts b/typescript/packages/core/src/http/httpFacilitatorClient.ts index 37bd2a0674..0e5f753f4e 100644 --- a/typescript/packages/core/src/http/httpFacilitatorClient.ts +++ b/typescript/packages/core/src/http/httpFacilitatorClient.ts @@ -334,9 +334,26 @@ export class HTTPFacilitatorClient implements FacilitatorClient { `Facilitator getSupported failed (${response.status}): ${responseExcerpt(errorText)}`, ); - // Retry on 429 rate limit errors with exponential backoff + // Retry on 429 rate limit errors with Retry-After header support if (response.status === 429 && attempt < GET_SUPPORTED_RETRIES - 1) { - const delay = GET_SUPPORTED_RETRY_DELAY_MS * Math.pow(2, attempt); + const retryAfter = response.headers.get("Retry-After"); + let delay: number; + if (retryAfter !== null) { + const retryAfterNum = Number(retryAfter); + if (!isNaN(retryAfterNum)) { + // 秒数として解釈してミリ秒に変換 + delay = retryAfterNum * 1000; + } else { + // HTTP-date として解釈して現在時刻との差分を計算 + const retryDate = new Date(retryAfter).getTime(); + delay = Math.max(0, retryDate - Date.now()); + } + // 安全上限: 最大30秒 + delay = Math.min(delay, 30_000); + } else { + // Retry-After がない場合は指数バックオフをフォールバックとして使用 + delay = GET_SUPPORTED_RETRY_DELAY_MS * Math.pow(2, attempt); + } await new Promise(resolve => setTimeout(resolve, delay)); continue; }