Shopify/omniauth-shopify-oauth2

Memoization - a potential cause for race conditions between threads.

yeoenggu opened this issue · 3 comments

In OmniAuth/Strategies/Shopify.rb - build_access_token method uses memoization which may cause a potential race condition. Refer to https://bearmetal.eu/theden/how-do-i-know-whether-my-rails-app-is-thread-safe-or-not/

  1. Supposed thread A has successfully build the token but yet to assign it to the instance variable.
  2. Thread B access the variable and since it is not yet set, it tries to build the token using same params. This result in error since code can only be used once.

I did have this bug occasionally where I received an error from Shopify. Unfortunately, I could not replicate it.

build_access_token overrides an upstream method that doesn't do any memoization, so I'm not sure why it would be unsafe to call more than once

This result in error since code can only be used once.

What error does this actually result in?

@EiNSTeiN- looks like he is referring to this method override that you added in #34. Why was that needed? Was that just a performance optimization?

I've investigated auth errors that we thought may be related to race conditions before. More from the browser side of things but this may be worth looking into is all I wanted to add.