Unhandled rejection when an in-flight certificate refresh fails after close

オープン 初心者向け
#656 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
nodejs, typescript
領域
backend

調査の方向性

内部の CloudSQLInstance 実装を cloud-sql-instance.js から確認し、scheduleRefresh()、forceRefresh()、close() に注目します。提供された再現手順を node --unhandled-rejections=strict repro.cjs で実行し、close 後に reject する進行中の refresh に関する回帰テストを追加します。完了基準は、refresh の待機処理が未処理の rejection なく終了すること、初期セットアップのエラーが引き続き呼び出し元に 전달されること、およびプロセスが稼働し続けることです。

索引モデルが issue の本文から書いたものです。

説明

Bug Description

forceRefresh() can join an in-flight background certificate refresh. If the instance is closed and the refresh then rejects, the refresh waiter settles but Node exits with an unhandled rejection. I reproduced this with clean installs of @google-cloud/cloud-sql-connector 1.12.1 and 1.13.1.

The expected behavior is for the SDK to handle the background rejection and allow the process to continue. A caller awaiting initial connector setup should still receive any setup error.

The example exercises the internal CloudSQLInstance refresh methods with a synthetic rejection. It runs without credentials, network access, or a database connection.

Example code (or command)

const { dirname, join } = require('node:path');
const { setImmediate } = require('node:timers/promises');

const packageName = '@google-cloud/cloud-sql-connector';
const sdkDir = dirname(require.resolve(packageName));
const { CloudSQLInstance } = require(join(sdkDir, 'cloud-sql-instance.js'));

async function main() {
  const instance = new CloudSQLInstance({
    options: { instanceConnectionName: 'example:us-central1:example' },
  });
  const started = Promise.withResolvers();
  const background = Promise.withResolvers();
  instance.performRefresh = () => {
    started.resolve();
    return background.promise;
  };

  instance.scheduleRefresh(0);
  await started.promise;
  const waiter = instance.forceRefresh();
  instance.close();
  background.reject(new Error('Simulated Cloud SQL Admin refresh failure'));
  await waiter;
  console.log('Refresh waiter settled.');
  await setImmediate();
  console.log('Process stayed alive.');
}
main();

Stacktrace

SDK 1.12.1
Refresh waiter settled.
repro.cjs:23
  background.reject(new Error('Simulated Cloud SQL Admin refresh failure'));
                    ^

Error: Simulated Cloud SQL Admin refresh failure
    at main (repro.cjs:23:21)

Node.js v24.22.1

Exit status was 1.

SDK 1.13.1
Refresh waiter settled.
repro.cjs:23
  background.reject(new Error('Simulated Cloud SQL Admin refresh failure'));
                    ^

Error: Simulated Cloud SQL Admin refresh failure
    at main (repro.cjs:23:21)

Node.js v24.22.1

Exit status was 1.

How to reproduce

Environment details
  • OS: macOS 27.2.1 (arm64)
  • Node.js version: 24.22.1
  • npm version: 11.19.1
  • Connector versions: 1.12.1 and 1.13.1
Steps to reproduce
  1. In a new directory, run npm init -y and npm install --save-exact @google-cloud/[email protected].
  2. Save the example as repro.cjs.
  3. Run node --unhandled-rejections=strict repro.cjs. The process exits after Refresh waiter settled. with exit status 1.
  4. Repeat in a separate directory with @google-cloud/[email protected].
主要言語
TypeScript
スター
99
フォーク
18
平均マージ
1日 23時間
マージ済み PR(30日)
20

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

GoogleCloudPlatform/cloud-sql-nodejs-connector のほかの issue

GoogleCloudPlatform/cloud-sql-nodejs-connector の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。