You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I realise this is a generic question which could apply to many similar situations but I thought I'd bring it up in case anyone thinks it's useful to mention it in createsend-ruby's README.md.
In multi-threaded applications, it is possible to get into an unsafe situation when refreshing tokens, e.g.:
record = SomeModel.find(...)
cs = CreateSend::CreateSent.new(
record.access_token,
record.refresh_token
)
begin
tries = 2
cs.clients
rescue CreateSend::ExpiredOAuthToken => e
access_token, expires_in, request_token = cs.refresh_token
record.access_token = access_token
record.request_token = request_token
record.save
retry if (trues -= 1).zero?
raise e
end
record.access_token expires
Thread A encounters ExpiredOAuthToken
Thread A calls #refresh_token
Thread B encounters ExpiredOAuthToken
Thread B calls #refresh_token but fails because record.refresh_token is now invalid
Thread A persists new token
Thread A continues
I'm assuming others have encountered this possibility. Anyone have any favoured suggestions for dealing with it?
I've created a question on SO too (modified the code to make it broader than createsend-ruby) if anyone would like some points!
The text was updated successfully, but these errors were encountered:
Thanks for reaching out. My name is Aidin and I am the Technical Lead for Integrations and APIs in Campaign Monitor. I would be more than happy to help out.
Were you able to find a solution for this particular issue?
I realise this is a generic question which could apply to many similar situations but I thought I'd bring it up in case anyone thinks it's useful to mention it in
createsend-ruby
's README.md.In multi-threaded applications, it is possible to get into an unsafe situation when refreshing tokens, e.g.:
record.access_token
expiresExpiredOAuthToken
#refresh_token
ExpiredOAuthToken
#refresh_token
but fails becauserecord.refresh_token
is now invalidI'm assuming others have encountered this possibility. Anyone have any favoured suggestions for dealing with it?
I've created a question on SO too (modified the code to make it broader than
createsend-ruby
) if anyone would like some points!The text was updated successfully, but these errors were encountered: