google-gax: native server-streaming cancellation can dispatch another RPC or throw before setup

オープン
#9,862 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
57/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
grpc, node.js, typescript

調査の方向性

Start in core/packages/gax/src/streamingCalls/streaming.ts, especially StreamProxy.cancel(), newStreamingRetryRequest(), and newMakeRequest(); trace how cancellation and retry timers interact. Add regression tests for the four cases listed in the issue, then run the gax package tests covering streaming calls. Done means early cancellation does not start or dereference a request, cancellation stops queued retries and cancels the active attempt, and normal retry and success still work.

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

説明

Summary

With native server-streaming retries enabled (gaxStreamingRetries: true), cancellation does not terminate the retry state machine:

  • Cancelling during retry backoff still dispatches the next RPC.
  • Cancelling before stream setup causes TypeError: Cannot read properties of undefined (reading 'cancel').
  • The active request's cancel method is copied onto the retry wrapper without binding its receiver.

Reproduced on main at c1c70497020b6d0552012a479f538a4b187196ac, macOS arm64, Node 24.22.3. This reproduction uses only local streams and fake timers; no Google Cloud service or credentials are involved.

Reproduction

After installing dependencies and compiling google-gax, run from core/packages/gax:

const {StreamProxy, StreamType} =
  require('./build/src/streamingCalls/streaming.js');
const {createDefaultBackoffSettings} = require('./build/src/gax.js');
const sinon = require('sinon');
const {PassThrough} = require('stream');

const retry = {
  retryCodes: [14],
  backoffSettings: {
    ...createDefaultBackoffSettings(),
    totalTimeoutMillis: undefined,
    maxRetries: 3,
    initialRetryDelayMillis: 100,
  },
};
const clock = sinon.useFakeTimers();
const requests = [];
const proxy = new StreamProxy(
  StreamType.SERVER_STREAMING, () => {}, false, true,
);
proxy.on('error', () => {});
proxy.setStream(() => {
  const stream = new PassThrough({objectMode: true});
  stream.cancel = sinon.spy();
  requests.push(stream);
  return stream;
}, {}, {}, retry);

requests[0].emit(
  'error', Object.assign(new Error('unavailable'), {code: 14}),
);
proxy.cancel();
clock.tick(100);
console.log(requests.length); // Actual: 2; expected: 1.
clock.restore();

const early = new StreamProxy(
  StreamType.SERVER_STREAMING, () => {}, false, true,
);
early.cancel();
early.setStream(
  () => new PassThrough({objectMode: true}), {}, {}, retry,
); // Throws TypeError reading 'cancel' from undefined.
Cause and proposed scope

StreamProxy.cancel() records _isCancelCalled only when this.stream is absent. Once the retry wrapper exists, cancellation therefore does not block a queued retry. newStreamingRetryRequest() does not retain/clear its retry timer and assigns retryStream.cancel = requestStream.cancel. Conversely, when cancellation happened before setup, the request factory returns undefined and newMakeRequest() immediately dereferences it.

I would like to contribute a narrowly scoped fix that owns cancellation in the native streaming retry state machine: preserve the active transport receiver when cancelling, prevent/clear scheduled retries, and handle cancellation before initialization without starting a request or dereferencing an absent stream. Regression tests would cover early cancellation, cancellation during backoff, cancellation of the current attempt after a retry, and normal retry/success behavior.

I checked the open PR list and cancellation-related PRs. #9359 changes normalCalls/retries.ts (unary calls), so it does not address this streaming path. This report concerns gRPC/native streaming retries, rather than the REST fallback transport issues.

Is this scope acceptable, and is anyone already implementing a fix for this streaming path?

主要言語
TypeScript
スター
3.2k
フォーク
732
平均マージ
2日 11時間
マージ済み PR(30日)
99

環境構築

はじめの一歩

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

googleapis/google-cloud-node のほかの issue

googleapis/google-cloud-node の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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