-
-
Notifications
You must be signed in to change notification settings - Fork 93
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
SystemStackError on selecting records from MySQL #309
Comments
I found that ancestor stack of relation class increased by every request. 46 response =
47 if arity < 0 || arity == args.size
48 p self.class.ancestors
49 super(*args, &mblock)
50 else
51 self.class.curried.new(self, view: name, curry_args: args, arity: arity)
52 end immediately after restarting puma:
after several requests from restarting puma:
FYI, the query log is here: (0.015262s) SELECT `tenants_users`.`tenant_uuid`, `tenants_users`.`user_uuid`, `tenants_users`.`role` FROM `tenants_users` WHERE ((`tenants_users`.`tenant_uuid` = 'development') AND (`tenants_users`.`user_uuid` = 'e960083f-ffc3-43d0-a7ff-b34716fad1fe')) ORDER BY `tenants_users`.`tenant_uuid`, `tenants_users`.`user_uuid` |
@tokichie how do you run this app locally? also via |
@solnic Yes. Also using puma locally (via #!/usr/bin/env puma
app_path = File.expand_path '../../', __FILE__
run_dir = ENV['HANAMI_ENV'] == 'development' ? '/tmp' : '/var/run'
environment ENV['HANAMI_ENV']
pidfile "#{run_dir}/puma.pid"
state_path "#{run_dir}/puma.state"
threads 0, 16
bind "unix://#{run_dir}/puma.sock" |
@solnic I found the root cause of this. I adopt multi-tenancy model for my app, so database is created for each tenant.
This means that I should re-create rom container with 2 gateways to account DB and tenant DB for each request according to credentials. I prepare the reproduction code: |
@tokichie you should not setup rom at run-time, esp that it's probably not thread-safe. What you can do instead, is setting up a basic configuration and then recreate it on each request, ie like this: # when booting
rom_base = ROM::Configuration.new(your_base_opts)
rom_base.auto_registration(...)
# at run-time (this assumes you made `rom_base` available somehow)
rom_config = ROM::Configuration.new(your_base_opts)
rom_config.register_relation(*rom_base.relation_classes) # do it with other components if you have them too
rom = ROM.container(rom_config) |
@solnic Thank you for work around. I try to use it. |
I applied the workaround to reproduction code, but output didn't change. Something wrong? |
@tokichie hmm damn, I'll have to debug this. Thanks for the gist. I'll get back to you. |
I'm using rom as ORM with Hanami.
Recently, I noticed that sometimes server hanged up raising SystemStackError.
I dug into stack trace, and found that
auto_curry
method was called too many times.Here is part of the trace:
And here is the caller:
Things that I know at this point are:
tenants_user_repository.find
method callsauto_curry
only once in local env.Here is the environment:
Versions:
The text was updated successfully, but these errors were encountered: