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

Ouverte
#9,862 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
57/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
grpc, node.js, typescript

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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?

Langage dominant
TypeScript
Étoiles
3.2k
Forks
732
Merge moyen
2 j 11 h
PR mergées (30 j)
99

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de googleapis/google-cloud-node

Toutes les issues de googleapis/google-cloud-node

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.