0

I’m trying to use FunWithFlags.enabled? (ref fwf) inside an absinthe middleware/3 callback but I got the following error:

(ArgumentError) argument error
    (stdlib) :ets.lookup(:fun_with_flags_cache, :some_flag)

Stacktrace:
  │ lib/fun_with_flags/store/cache.ex:35: FunWithFlags.Store.Cache.get/1
  │ lib/fun_with_flags/store.ex:12: FunWithFlags.Store.lookup/1
  │ lib/fun_with_flags.ex:77: FunWithFlags.enabled?/2

I haven’t tried too much. I just narrowed down where the issue is happening. I’m guessing the middleware compiles before the :some_flag record (or maybe the :fun_with_flags_cache table) is created and then failed because there is no record/table.

This link says:

It stores flag information in Redis or a relational DB (PostgreSQL or MySQL, with Ecto) for persistence and synchronization across different nodes, but it also maintains a local cache in an ETS table for fast lookups. When flags are added or toggled on a node, the other nodes are notified via PubSub and reload their local ETS caches.

I already tried to disable the ETS with the following config:

config :fun_with_flags, :cache,
  enabled: false,

But I didn't work. :(

Here is an example of how I'm using it:

defmodule MyApp.Schema do
use Absinthe.Schema
...
  def middleware(middleware, field, object) do
  FunWithFlags.enabled?(:some_flag) # <-- (ArgumentError) argument error (stdlib) :ets.lookup...
  ...
  end
end

Thanks!

catra
  • 178
  • 2
  • 11
  • Make sure `:fun_with_flags` application gets started **before** you reference it. Without seeing more code it’s impossible to narrow the issue down better. – Aleksei Matiushkin Sep 23 '21 at 03:31
  • Hi @AlekseiMatiushkin, thanks for your replying. I added an example of how I'm using it. What you said makes sense. Do you have any idea of how I can do that? The only places where I see FunWithFlags is on `mix.exs` and `config.exs`. The first one is to add the dependency and the second to set some configurations. – catra Sep 23 '21 at 12:27

1 Answers1

0

Since the documentation explicitly mentions possible race conditions, I’d suggest you start the FwF application manually as described in Application Start Behaviour section of the documentation.

In mix.exs:

- {:fun_with_flags, "~> 1.6"},
+ {:fun_with_flags, "~> 1.6", runtime: false},

and in your Application.start/1 callback:

  def start(_type, _args) do
    children = [
      ...,
+     FunWithFlags.Supervisor,
    ]

    opts = [strategy: :one_for_one, name: MyApp.Supervisor]
    Supervisor.start_link(children, opts)
Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160
  • It sounds promising but I tried both options (A and B) proposed on the repo but no luck yet. I also, delete the `deps` and the `_build` directories. I used `mix clean`. If you have an app using Absinthe could you confirm that after doing that works or not? Thanks in advance. Muchas gracias por tu respuesta! – catra Sep 23 '21 at 14:15