Closed xenoterracide closed 2 years ago
This is by design -- the readme mentions onFailure
is not called on timeout:
timeout.onFailure(callback)
An event emitter that fires whenever a function throw an error or returns an errorful result. It's invoked with the duration of the call, the reason for the failure, and an boolean indicating whether the error is handled by the policy.
This is only called when the function itself fails, and not when a timeout happens.
Likewise onTimeout
is called only for timeouts, not for failures.
The logic being it's easier to 'combine' the two events if you need a count of both together, but it's hard to separate them.
maybe what's not clear here is what, outside of a timeout, is considered an error/failure for timeout? To me it would seem like the timeout is the failure there.
Hm, I agree that it might be a little less apparent for timeout. onFailure
is implement by all policies, and might be easier to explain in the context of retries: whenever the inner function is invoked and it throws something (or returns an errorful result), then onFailure
is called. The retry policy might keep retrying, until onGiveUp
fires.
onSuccess
and onFailure
are provided from the "executor" that report how the function itself gets called and are separate from any events the policy itself might implement.
Right, but what does ontimeout do that does not meet that criteria? I think that's where my confusion comes in. How is ontimeout not just the thing that is throwing the failure...
this is the relevant part of our logs, you can see
onFailure
is called but there's no call toonTimeout
here's the
BreakerProvider