-
Notifications
You must be signed in to change notification settings - Fork 316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
addresses a possible race condition with purchase completed callbacks #313
addresses a possible race condition with purchase completed callbacks #313
Conversation
self.purchases!.purchasePackage(package) { _,_,_,_ in | ||
self.purchases!.purchasePackage(package) { (tx, info, error, userCancelled) in | ||
receivedError = error as NSError? | ||
secondCompletionCalled = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the error case - while the completion block is running, it hasn't been removed from the list of completion blocks, and so initiating a new purchase will fail.
I confirmed that this test fails on develop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!
self.purchases!.purchasePackage(package) { _,_,_,_ in | ||
self.purchases!.purchasePackage(package) { (tx, info, error, userCancelled) in | ||
receivedError = error as NSError? | ||
secondCompletionCalled = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!
@synchronized (self) { | ||
completion = self.purchaseCompleteCallbacks[transaction.payment.productIdentifier]; | ||
self.purchaseCompleteCallbacks[transaction.payment.productIdentifier] = nil; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for fixing the productIdentifier thing, that was bad from me
if (productIdentifier) { | ||
self.purchaseCompleteCallbacks[productIdentifier] = nil; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's funny, this is exactly what you said the other day that could break
There was a race condition in
handleReceiptPostWithTransaction:purchaserInfo:subscriberAttributes:error:
.The issue was that in the order of operations, we were:
If the completion block performed in 2. does something like initiate another purchase, it would access the callbacks list before it got removed in 3, and then the code would see that there's already a completion block for the product and return the
RCOperationAlreadyInProgressError
.might address #291, but it's not guaranteed to since I'm not sure that this was the original issue.