3.0.13
Two fixes backported from 4.0, and a deprecation notice on everything 4.0 renames or removes. Nothing is removed here and
no signature changes, so there is nothing to do on upgrading; the 3.x series stays supported for PHP 7.1 and above.
Fixed
- Timeouts no longer overflow. Doubling was an uncapped bit shift, which broke down in three ways once enough attempts
were configured: from the 46th attempt on the timeout left the integer range and
ExponentialBackoff::getTimeoutMicroseconds() threw a TypeError; from the 65th on, shifting by more than the width
of an integer returned 0 and silently disabled the backoff; and a non-positive iteration raised an ArithmeticError.
All three were reachable through ::setMaxAttempts(), and none could be caught by ::run(), which handles exceptions
rather than errors. Two further ways in through the static methods themselves: a negative initial timeout reached
random_int(0, -n)and raised an Error, and an initial timeout large enough that converting it to microseconds
overflowed made ::getTimeoutSeconds() hand a float to anintparameter. Timeouts now stop below what an integer
holds instead of growing past it, and an iteration below the first is treated as the first one. Every timeout that
worked before is unchanged: verified against the old shift across 356 combinations, covering each iteration the shift
handled correctly for seven different initial timeouts, with no differences. Unlike 4.0, this series keeps uncapped
doubling and randomness of up to 10%. - Whether to wait in non-blocking mode is now decided per wait instead of once at construction. An instance built
outside a coroutine — a service put together during bootstrap, say — used to block for the rest of its life even once
coroutines were using it, which is the way it is normally wired up in a Swoole application. Asking for a mode outright
still skips the detection entirely.
Deprecated
Nothing listed here goes away in 3.x. It is marked so that a 4.0 upgrade is a matter of following the notices rather
than reading a diff; see the new Upgrading to 4.0 section of README.md for the full table.
- Method AbstractRetryCondition::met(), which 4.0 renames to ::shouldRetry() and inverts: TRUE means "try again"
there, where here it means "stop". The signatures are compatible either way round, so a condition class carried across
with nothing changed but the method name will retry in exactly the cases it used to stop in, with nothing to warn you.
Negate the body along with the rename. - Constants ExponentialBackoff::TYPE_MICROSECONDS and ExponentialBackoff::TYPE_SECONDS, along with methods
::getType() and ::setType(). 4.0 measures every delay in microseconds; set the length directly with
::setInitialDelay(), for whichsetType(TYPE_SECONDS)becomessetInitialDelay(1000000). - Method ExponentialBackoff::getTimeoutMicroseconds(), renamed to ::getDelayMicroseconds() in 4.0, where it takes
the cap and the kind of randomness as two further parameters. - Method ExponentialBackoff::getTimeoutSeconds(), which 4.0 removes. Divide the result of ::getDelayMicroseconds()
by 1000000 where seconds are wanted, passing Jitter::None to get a fixed value rather than a randomized one. - The second parameter of ExponentialBackoff::__construct(), which becomes a nullable CrowdStar\Backoff\Mode in 4.0:
Mode::Blocking for the default SAPI, Mode::Swoole for the Swoole one. Passing nothing keeps meaning the same thing
in both. - Methods ExponentialBackoff::getCurrentAttempts(), ExceptionBasedCondition::getException() and
ExceptionBasedCondition::setException() were already deprecated; their notices now name 4.0 as the version that
removes them, and point at the replacement where there is one.