connect-es icon indicating copy to clipboard operation
connect-es copied to clipboard

AbortSignal rejects with Code.Internal instead of Code.Canceled

Open polRk opened this issue 11 months ago • 3 comments

Describe the bug

It seems to me that if I use AbortSignal.timeout(), then the call should end with the error canceled/deadline, not internal.

To Reproduce


client.method(msg, {signal: AbortSignal.timeout(0)})
// ConnectError: [internal] The operation was aborted due to timeout. code: 13

Environment (please complete the following information):

  • @connectrpc/connect-node version: 2.0.2
  • Node.js version: v22.14.0

** connect source codes

    /**
     * An optional AbortSignal to cancel the call.
     * If cancelled, an error with Code.Canceled is raised.
     */
    signal?: AbortSignal;

Missing handling TimeoutError in ConnectError.from

ConnectError.from(reason, code)

polRk avatar Mar 23 '25 10:03 polRk

#1454

polRk avatar Mar 23 '25 10:03 polRk

It's very unfortunate that AbortSignal.timeout doesn't provide access to the remaining time. A gRPC / Connect deadline is typically set on the client and sent to the server in a request header, so that deadlines can be propagated. Both server and client will error with deadline_exceeded. I'd recommend to use the timeoutMs client option instead of AbortSignal.timeout if possible.

This behavior however still looks like a bug that should be fixed:

client.method(msg, {signal: AbortSignal.timeout(0)})
// ConnectError: [internal] The operation was aborted due to timeout. code: 13

Because of the specific behavior of deadlines, I believe that the error should be canceled, notdeadline_exceeded. (See Error Codes in the Connect Protocol.)

Let me double check.

timostamm avatar Apr 03 '25 14:04 timostamm

Yes, we have to use code canceled for TimeoutError.

timostamm avatar Apr 29 '25 10:04 timostamm

Implemented in https://github.com/connectrpc/connect-es/pull/1526.

timostamm avatar Jul 09 '25 13:07 timostamm