Skip to content

generator: generated methods return a promise without .cancel() since request/response logging was added #9790

Open

Description

@aelmanaa

Library Name: all generated clients, for example @google-cloud/kms (generator: core/generator/gapic-generator-typescript)

Try this API: Not applicable. The problem is the promise the client returns, not the API response.

Repro link: https://gist.github.com/aelmanaa/09946f41f4779c59c4d324e40d6827d2

Steps:

  1. Start a local HTTP server that waits 2 s before it answers.
  2. Create KeyManagementServiceClient({fallback: true, protocol: 'http', apiEndpoint: '127.0.0.1', port, authClient: new PassThroughClient()}).
  3. Run const p = client.asymmetricSign(request) and check typeof p.cancel.
  4. After 200 ms, call p.cancel() if it exists.

Description:
client-libraries.md in gax says a method's returned promise can be cancelled with promise.cancel(). Generated clients no longer return that promise. To log the response, each method now returns this.innerApiCalls.X(request, options, wrappedCallback)?.then(...). .then() returns a plain Promise, so the OngoingCallPromise from gax and its cancel() are lost.

Results with the repro (Node 24, REST fallback):

  • @google-cloud/kms 4.5.0 (gax 4.6.1): typeof p.cancel is function. cancel() closes the connection immediately.
  • @google-cloud/kms 5.0.0 (gax 5.0.8) and packages/google-cloud-kms on main (0435467, gax 6.14.0): typeof p.cancel is undefined. The request runs until the server answers.
  • On main, client.innerApiCalls.asymmetricSign(request, {}) still returns a promise with cancel(), and it aborts the fetch.

This came from the logging template change in googleapis/gapic-generator-typescript#1671. The ?.then(...) wrapper is in templates/{cjs,esm}/.../src/$version/$service_client.ts.njk for normal, LRO, diregapic LRO and paged methods.

#9462 added CallOptions.signal, not released yet. With gax main, client.asymmetricSign(request, {signal}) aborts the request because options still reaches gax. So a way to cancel is coming, but the documented one is broken.

Expected: one of:

  • The returned promise keeps cancel(), for example by copying cancel from the inner promise onto the .then() result and typing the return as gax.CancellablePromise<...>.
  • client-libraries.md drops promise.cancel() and documents options.signal once gax 6.15.0 is out.

I can send a PR for either.

Why: core/packages/gax/client-libraries.md ("Regular methods") documents promise.cancel(), and it worked before the logging change.

Versions: google-cloud-node main 0435467, @google-cloud/kms 6.3.0, google-gax 6.14.0, Node 24.21.0.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions