connor4312 / cockatiel

🐦 A resilience and fault-handling library. Supports Backoffs, Retries, Circuit Breakers, Timeouts, Bulkhead Isolation, and Fallbacks.
MIT License
1.59k stars 50 forks source link

Custom abort signals throw TaskCancelledException without "reason" #101

Closed VentuzVictorPerez closed 1 week ago

VentuzVictorPerez commented 1 month ago

First of all, great library, thank you for your contribution.

However, I've noticed a situation that I believe is a bug.

Custom abort signals throw the TaskCanceledException and do not show any reason even when one has been assigned.

Please see the following example:

https://codesandbox.io/p/sandbox/cnd5xw

I have two buttons, one that starts the retries execution and another that cancels said execution.

When adding a custom abort signal to "execute" like this:

result = await wrap(timeoutPolicy, retryPolicy).execute( () => slowTask(20000), abortController.signal );

And then aborting it with a reason (from the button):

abortController.abort(canceledWithButtonReason);

The exception is TaskCanceledExceptionwith the messageOperation timed out after 20000ms when this is not true. The execution was canceled because the user wanted it to via the button, the timeout had not yet expired.

Additionally, the provided reason ("Canceled from button") is not returned in the exception (it is undefinedthere).

I am using aggressive timeouts, and the "onTimeOut" callback is also triggered in this case, which I also believe is an error.

In Cooperative timeouts this is even worse, no exception is throwed when I abort my custom signal.