Flagsmith / flagsmith-ruby-client

Ruby Client for Flagsmith. Ship features with confidence using feature flags and remote config. Host yourself or use our hosted version at https://www.flagsmith.com/
https://www.flagsmith.com/
BSD 3-Clause "New" or "Revised" License
11 stars 6 forks source link

Rails apps with puma on cluster mode not catching up flag changes when local evaluation is enabled #62

Open Guilherme2112 opened 4 months ago

Guilherme2112 commented 4 months ago

Context

When the following conditions are met, the local environment of the rails server does not refresh the flag states...the environment document request actually happens, tough.

Steps to reproduce

Useful info

Example project

https://github.com/Guilherme2112/flagsmith-rails-example

(basic instructions at README)

zachaysan commented 4 months ago

Thanks for the well written issue @Guilherme2112. It's not immediately clear to me as to why this would happen and I've sadly never used Puma before. Do you have any guesses or insights as to what would cause this? My initial suspicion would be some sort of threading issue, but I'm really only grasping at straws here.

Guilherme2112 commented 4 months ago

@zachaysan I also believe it is some kind of threading issue, but I can't pinpoint what it is...I would bet on something related to the puma child process forking and the rails initialization...app preload may play a role too šŸ¤”

Guilherme2112 commented 3 months ago

@zachaysan what I managed to do to get around the problem was to create a singleton class containing the client and only call for an instance when needed...this way there was no interaction between puma threads and the flagsmith client (likely the background polling thread or the mutex part)

And to my surprise, it looks pretty close to what the competitor does (šŸ˜…) , so it may be pointing towards a solution?

(edit: english is not my mother tonge so here's a disclaimer if the tone sound inapropriate, I don't mean to)