-
Notifications
You must be signed in to change notification settings - Fork 25
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 not being cleaned up, causes application crash #40
Comments
Ouch... this really is a bad strategy... I will probably try to address this on next version (2.0). The proper fix here might be to handle initialization asynchronously. We could use There is some churn in this repo right now and I am gathering some feedback about breaking changes here so that I can release a 2.0 version of this library. This will, certainly, get into that list but I can't promise a schedule right now... If you want to try handling this on a PR with an async initialization it will be most welcome. |
Something to note: this also happens where the table doesn't exist. Doing a quick view through the code, this likely related to the initialization of the table being done in a task and creating a race condition on restarts, as well. I can't find the exact reason for the table not existing as this is currently happening in local dev and it just randomly occurs with no logs generated. I don't think making initialization async (task or handle_continue) for any of this is feasible as it introduces another race condition. It can be presumed that users will not want their app to start if user access verification isn't available, so it should always be a blocking operation by default.
|
From the code, it seems like the I don't think a race condition can exist there. The reason I looked this up is because we have the problem of our Elixir Phoenix app not starting (sometimes) and the error we get is that |
@Sgoettschkes said:
|
So, I've used the base work from @lovebes and refactored it a bit. I believe that what we have currently in #48 should solve issues here. The only way it would STILL show this exception is by registering two process by doing something like: Supervisor.child_spec(MyStrategy, id: :id_1),
Supervisor.child_spec(MyStrategy, id: :id_2) This would still make it impossible to initialize the cache because it we are using the module name to do that and on both the module is the same. It would still break in an awkward way with Can anyone here try it locally before I release a new version? You can do that with a github dep passing the PR branch like: # in mix deps
{:joken_jwks, github: "joken-elixir/joken_jwks", branch: "feat/better_process_integration"} P.S.: thanks once again to everyone's trying to figure this one out! OSS for the win! |
I have only seen this in local dev with code reloading on, so this makes sense. 👍🏻 |
I am experiencing the same issue in a Phoenix application. For the time being I am initializing the strategy with I also want to mention that I am seeing this in my local dev with code reloading enabled. |
Hi @alolis ! Can you try the branch I've mentioned? Just to check if it works :) THanks! |
Hi @victorolinasc! Just gave it a try and I am getting Am I supposed to install something else in order for the branch to work? |
@alolis this is strange as we haven't touched adapter configuration. By default we use a Tesla request configuration and it uses |
@victorolinasc , I have completely removed my If I keep both dependencies (probably is wrong) in my
The refered
Let me know if I am doing something really really wrong :) |
Any update on the fix for this? I'm having to restart
|
I created a fix PR: #68 to prevent table creation if ETS table already exists. That will at least not trigger the |
All the process work is now published as I f you people can test it It'd be very helpful! A small changelog is:
If you need to disable specific logging from the library, you can use default
Tesla has its own middleware for telemetry events. We should just use that :)
|
Hi, I've noticed that my application is crashing periodically. I've tracked down this library as at least contributing to the crash. For whatever reason my supervisor is attempting to restart my JWK strategy but it cannot because the ETS table that it wants to create already exists:
I'm not sure why it's being restarted in the first place (I think it is happening after a recompile in dev), but the supervisor is unable to start the JWK strategy and it reaches the retry policy limits which in turn crashes the parent supervisor and ultimately the whole application.
Looking at the implementation I see that the ets table is being created in the
start_link
function of the strategy: https://github.com/joken-elixir/joken_jwks/blob/master/lib/joken_jwks/default_strategy_template.ex#L190Since that start_link is being called by my supervisor, it means that the supervisor owns the table. Therefore whenever the strategy itself restarts under the supervisor, it tries to re-create the ets table and fails. I think the ets table should probably be started by the actual worker process here.
I think a workaround for me is to check if the table exists in an
init_opts
callback and delete it if it already exists. I would be glad to submit a PR to fix the underlying problem, but looking at the actual code I'm a bit curious why it's not just using genserver? That would make this a bit simpler to solve since the table could be created in the genserver'sinit
callback.The text was updated successfully, but these errors were encountered: