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

未关闭 适合新手
#656 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
nodejs, typescript
领域
backend

调研方向

从 cloud-sql-instance.js 中的内部 CloudSQLInstance 实现开始,重点关注 scheduleRefresh()、forceRefresh() 和 close()。使用 node --unhandled-rejections=strict repro.cjs 运行提供的复现用例,然后添加一个回归测试,覆盖 close 之后被拒绝的进行中 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 小时
30 天内合并 PR
20

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

GoogleCloudPlatform/cloud-sql-nodejs-connector 的其他 Issue

查看 GoogleCloudPlatform/cloud-sql-nodejs-connector 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。