purchases-ios icon indicating copy to clipboard operation
purchases-ios copied to clipboard

`Backend`: fixed potential race conditions introduced by `OperationDispatcher.dispatchOnWorkerThread(withRandomDelay:)`

Open NachoSoto opened this issue 2 years ago • 0 comments

Fixes CSDK-391. As described in that ticket, calling a method that introduces a random delay before performing an API request could lead to a race condition. Example:

Request 1: delay 0 seconds. Start now. Request 2: delay 2 seconds. Waiting… Request 1 finishes. Request 2: 2 seconds past. There is no in progress request, so we start it again

This also solves CSDK-394. If any part of our code (or users) call a method that would enqueue a request multiple times, we need to insert it into the callback queue right away. That's what this does: it moves the random delay to after the callback has been added to the CallbackCache.

NachoSoto avatar Aug 13 '22 19:08 NachoSoto