Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unhandledRejection when aborting a server stream using connect-node #476

Closed
ghost opened this issue Feb 21, 2023 · 2 comments
Closed

unhandledRejection when aborting a server stream using connect-node #476

ghost opened this issue Feb 21, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@ghost
Copy link

ghost commented Feb 21, 2023

Hello!

I have the impression that with connect-node, when you abort a server stream call via an AbortSignal, it leads to an unhandledRejection systematically.

Is it a bug, or am I using the library incorrectly?

Thank you very much in advance!

To Reproduce

import {
  createGrpcTransport,
  createPromiseClient,
} from "@bufbuild/connect-node";

import { ElizaService } from "@buf/bufbuild_eliza.bufbuild_connect-es/buf/connect/demo/eliza/v1/eliza_connect.js";

const transport = createGrpcTransport({
  baseUrl: "https://demo.connect.build",
  httpVersion: "2",
})

const client = createPromiseClient(ElizaService, transport);

try {
  const abort = new AbortController();

  for await (const response of client.introduce({name: "Johyn"}, { signal: abort.signal })) {
    console.log('response', response);
    abort.abort();
  }
} catch (e) {
  console.log('error', e);
}
response IntroduceResponse { sentence: "Hi Johyn. I'm Eliza." }
error ConnectError: [canceled] The operation was aborted
    at connectErrorFromReason (file:///home/johynpapin/Projets/gabie/clienttest/node_modules/@bufbuild/connect-core/dist/esm/connect-error.js:99:20)
    at connectErrorFromNodeReason (file:///home/johynpapin/Projets/gabie/clienttest/node_modules/@bufbuild/connect-node/dist/esm/private/node-error.js:48:12)
    at Promise.reject (file:///home/johynpapin/Projets/ga
bie/clienttest/node_modules/@bufbuild/connect-node/dist/esm/private/node-universal-client.js:285:63)
    at ClientHttp2Stream.h2StreamError (file:///home/johynpapin/Projets/gabie/clienttest/node_modules/@bufbuild/connect-node/dist/esm/private/node-universal-client.js:225:
22)
    at ClientHttp2Stream.emit (node:events:524:35)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  rawMessage: 'The operation was aborted',
  code: 1,
  metadata: HeadersList {
    cookies: null,
    [Symbol(headers map)]: Map(0) {},
    [Symbol(headers map sorted)]: null
  },
  details: [],
  cause: undefined
}
node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

ConnectError: [canceled] The operation was aborted
    at connectErrorFromReason (file:///home/johynpapin/Projets/gabie/clienttest/node_modules/@bufbuild/connect-core/dist/esm/connect-error.js:99:20)
    at connectErrorFromNodeReason (file:///home/johynpapin/Projets/gabie/clienttest/node_modules/@bufbuild/connect-node/dist/esm/private/node-error.js:48:12)
    at Promise.reject (file:///home/johynpapin/Projets/gabie/clienttest/node_modules/@bufbuild/connect-node/dist/esm/private/node-universal-client.js:285:63)
    at ClientHttp2Stream.h2StreamError (file:///home/johynpapin/Projets/gabie/clienttest/node_modules/@bufbuild/connect-node/dist/esm/private/node-universal-client.js:225:22)
    at ClientHttp2Stream.emit (node:events:524:35)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  rawMessage: 'The operation was aborted',
  code: 1,
  metadata: Headers {
    [Symbol(headers list)]: HeadersList {
      cookies: null,
      [Symbol(headers map)]: Map(0) {},
      [Symbol(headers map sorted)]: null
    },
    [Symbol(guard)]: 'none'
  },
  details: [],
  cause: undefined
}

Node.js v19.6.0

Environment

  • @bufbuild/connect-node version: 0.7.0
  • Node.js version: 19.6.0

Additional context

This prevents me from properly testing an API using Jest.

@ghost ghost added the bug Something isn't working label Feb 21, 2023
@timostamm
Copy link
Member

This is indeed a bug. The raised ConnectError: [canceled] The operation was aborted is expected, the unhandled promise rejection is not. Thank you for the report!

@timostamm
Copy link
Member

Fixed by #530. Thank you @johynpapin!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant