Error with FunWithFlags after deployments

I’m working on a Phoenix application that uses the FunWithFlags library. The problem is that after each deployment for a brief amount of time, some requests will fail to complete due to the following error:

* 1st argument: the table identifier does not refer to an existing ETS table
(stdlib 6.0) :ets.lookup(:fun_with_flags_cache, :my_flag_example)
 (fun_with_flags 1.12.0) lib/fun_with_flags/store/cache.ex:49: FunWithFlags.Store.Cache.get/1
  (fun_with_flags 1.12.0) lib/fun_with_flags/store.ex:12: FunWithFlags.Store.lookup/1
lib/fun_with_flags.ex:86: FunWithFlags.enabled?/2

This error happens in various places: sometimes in plugs used in our routes, other times in jobs that will be running while the deployment is happening. We are using AWS and rolling updates. The error appears when a new instance goes up and the FunWithFlags table is not set in ETS, but I’m not sure how to fix it. I followed the instructions in the library to make the initialization inside the application GitHub - tompave/fun_with_flags: Feature Flags/Toggles for Elixir

Here’s the code in the app for the initialization of the library:

application.ex

children = [
...
FunWithFlags.Supervisor,
...
]

Supervisor.start_link(children, opts)
  def project do
    [
      app: :my_app,
      version: "0.1.0",
      elixir: "~> 1.17",
      elixirc_paths: elixirc_paths(Mix.env()),
      compilers: Mix.compilers(),
      start_permanent: Mix.env() == :prod,
      aliases: aliases(),
      deps: deps(),
      releases: [
        my_app: [
          applications: [
            fun_with_flags: :load,
            fun_with_flags_ui: :load
          ]
        ]
      ]
    ]
  end

defp deps do 
[
...
      {:fun_with_flags, "~> 1.12", runtime: false},
      {:fun_with_flags_ui, "~> 1.0", runtime: false},
...
end
]

I would expect more people to have run into this problem but I searched in the forum and the library issue and didn’t find anything related to it. Thanks in advance

How do you deploy? Can you delay sending traffic to the backend for 20s or so?

Basically there are two options:

  1. (Preferred) if you can delay sending traffic to your app, do that. This can be configured on Kubernetes for example.

  2. If you use some sort of PAAS that doesn’t have liveness/readiness probes like Kubernetes, you can delay starting the Endpoint supervisor. I have a code somewhere as I did that for an app that used to be deployed on Heroku/Gigalixir. I can dig it out for you if you can’t do 1)