-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Recursive Schema.execute
call blocks forever with dataloader
#4235
Comments
Hi, sorry for the trouble! I would like to support re-entry, but I never actually considered it before. I'll take a look soon -- the best approach I can think of is to add a test for this scenario and start tweaking things until it works again... |
I tried adding a basic test for this in 3c35bc8 and it worked fine with a blocking dataloader, with Ruby-based scheduler and with That made me wonder, what are you using for |
Now, I am wondering, maybe I am doing something wrong. We are NOT using a scheduler and we DON'T have option |
Derp, sorry -- I read The test I added also covers Could you try debugging with For another example of how that's done, I'm debugging a similar issue with Rspec right now where I used |
Cool. Thanks for the tips – I will try that next week. |
I am not getting much from
We will upgrade to rails 7 soon, maybe it will help? |
After upgrading to rails 7 and latest ruby graphql (2.0.22) I am getting an error instead of infinite lock. This is still without
|
@tchak did you find any workaround for the problem? We're running into exactly the issue and have a similar case. The situation might get better with https://blog.saeloun.com/2022/02/23/rails-fiber-safe-connection-pools/ but it's not yet released. EDIT: Looks like we need to wait for Rails v7.1 - rails/rails@ea54939 rails/rails#46553 (looks all related) |
I ran into this issue, or maybe just a similar one. It came down to trying to use an ActiveRecord dataloader within a transaction. The transaction acquires an exclusive lock on the database connection. The dataloader source then runs in a separate fiber and needs to also acquire a lock on the connection to run the query. This second lock deadlocks. My fix was to avoid using the dataloader within transactions. To catch future instances of this problem without suffering the deadlocks, I am checking the lock in my dataloader source before attempting a query: class ActiveRecordSource < GraphQL::Dataloader::Source
attr_reader :model_class
def initialize(model_class)
@model_class = model_class
end
def fetch(ids)
if model_class.connection.lock.mon_locked? && !model_class.connection.lock.mon_owned?
raise "cannot use dataloader within transaction"
end
instances = model_class.where(id: ids).index_by(&:id)
ids.map { |id| instances[id] }
end
end I think the proper solution for this is to have |
Hey, sorry we never got to the bottom of this. @btoews, thanks for sharing what worked for you. Hopefully that will help others who are using Dataloader within a transaction. Rails 7.1 has |
Describe the bug
We are in the process of updating
graphql
gem and migrating to usedataloader
(nonblocking: false
). We run into an issue that comes up due to a bit of weirdness in our application. Some of our mutations during their execution callSchema.execute
(we use graphql queries as serialization for objects on our audit logs). What happens is that calls todataloader
during this execution inside mutations block forever. Not really knowing what I am doing, I tried to pass a newdataloader
instance to the internal execute call context. It solved the blocking forever problem but now I am getting an empty data hash from the internal execute with no errors. I can provide more details if needed, but maybe it's absolutely terrible and unreasonable what we are doing ?Versions
graphql
version: 1.13.6 and 2rails
: 6.1.6.1The text was updated successfully, but these errors were encountered: