`unhandledRejection` when aborting a server stream using `connect-node`

This issue has been tracked since 2023-02-21.

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.

timostamm wrote this answer on 2023-02-28

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 wrote this answer on 2023-03-16

Fixed by #530. Thank you @johynpapin!

More Details About Repo
Owner Name bufbuild
Repo Name connect-es
Full Name bufbuild/connect-es
Language TypeScript
Created Date 2022-02-16
Updated Date 2023-03-20
Star Count 851
Watcher Count 20
Fork Count 33
Issue Count 18

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date