Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ETS table from eredis_cluster_monitor not found at start-up #63

Open
luiz-firework opened this issue Jul 7, 2022 · 5 comments
Open

Comments

@luiz-firework
Copy link

Hi, here's a summary of what's been happening:

  • I have an app (inside an umbrella) that provides cache for the other applications (we call it redis_cache). It depends on :eredis_cluster.
  • :redis_cache is loaded as a dependency on the main application
  • I have a library that uses :redis_cache as a backend and is also a dependency of the main application. This library starts a genServer that reads from redis_cache at initialization. Everything is started in proper order.

However, when trying to boot the application in staging, I'm getting the below error and the system crashes.

** (ArgumentError) errors were found at the given arguments:

  * 1st argument: the table identifier does not refer to an existing ETS table

    (stdlib 3.17.2) :ets.lookup(:eredis_cluster_default, :cluster_state)
    (eredis_cluster 0.8.0) src/eredis_cluster_monitor.erl:71: :eredis_cluster_monitor.get_state/1
    (eredis_cluster 0.8.0) src/eredis_cluster.erl:623: :eredis_cluster.query/4
    (redis_cache 0.1.0) lib/redis_cache/adapters/eredis_cluster.ex:9: RedisCache.Adapters.EredisCluster.command!/1
    (redis_cache 0.1.0) lib/redis_cache/store/redis.ex:18: RedisCache.Store.Redis.get/1
    (ex_rate_limiter 0.1.5) lib/ex_rate_limiter/dynamic_limits_server.ex:62: anonymous fn/2 in ExRateLimiter.DynamicLimitsServer.get_cache_values/0
    (elixir 1.13.3) lib/enum.ex:2396: Enum."-reduce/3-lists^foldl/2-0-"/3
    (ex_rate_limiter 0.1.5) lib/ex_rate_limiter/dynamic_limits_server.ex:61: ExRateLimiter.DynamicLimitsServer.get_cache_values/0

If :eredis_cluster has been started at this point, how come the ETS table for eredis_cluster_monitor isn't present yet?

Please let me know if you need more details and thanks!

@zuiderkwast
Copy link
Collaborator

zuiderkwast commented Jul 7, 2022

Hi Luiz! Tudo bem?

The ETS table is created in init if you have a config file that defines where eredis_cluster should connect to, for example your umbrella app config file. Otherwise, it is created in eredis_cluster:connect/1,2. Maybe your config file is not found?

@luiz-firework
Copy link
Author

Tudo bem! :)
we have that config set-up and it works fine as long as I don't need to reach the cache at start-up, as with my newly added dependency.

After trying many things, I was able to make it work by placing :eredis_cluster in extra_applications (Elixir) on my main app mix.exs, but that's not a permanent solution as my redis_cache should be the one starting it. I'm wondering if :eredis_cluster_monitor might be being started async.

@zuiderkwast
Copy link
Collaborator

I think the eredis_cluster application needs to be started before the other application where you use it during init, so it's already started when you use it.

I don't know how to do that in an Erlang release, even less in Elixir, sorry! 😬

If you figure it out, please post the solution here for future reference.

@zuiderkwast
Copy link
Collaborator

After thinking about it a bit more, I think you should make eredis_cluster a dependency of redis_cache, i.e. add it in the app file under applications.

https://www.erlang.org/doc/man/app.html (Erlang, but I suppose it's similar for Elixir)

applications

All applications that must be started before this application. If an application is also listed in optional_applications, then the application is not required to exist (but if it exists, it is also guaranteed to be started before this one).

systools uses this list to generate correct start scripts. Defaults to the empty list, but notice that all applications have dependencies to (at least) Kernel and STDLIB.

@zuiderkwast
Copy link
Collaborator

I'm wondering if :eredis_cluster_monitor might be being started async.

I don't think so. It is part of the supervision tree of eredis_cluster so it should be started synchronously.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants