interesting. I think it may be, but it’s a bit complicated. The load itself does a read which has a timeout on it, and I don’t think we do anything to indicate to load read actions that they should adopt the parent’s timeout, and its not entirely clear if they should adopt the parent’s timeout TBH. Its…unclear
You could conditionally add the timeout in the target action for only when its being run directly by switching on the presence of query.context[:accessing_from] I believe.
But if I don’t specify a read_action then the load would respect the timeout value correct?
At least that is what I would expect from a timeout field in a load call haha. And, of course, if that is the case, I would expect the same to be true if the read_action is set as that is just a implementation detail that the caller (the one doing the load) doesn’t need to concern about it.
I actually think that this particular behavior is more correct, considering multiple options. The concept is that when loading relationships we honor the rules on the relevant read action. That action is, by default, the primary read action. You’ve set a timeout on that read action, which means it applies when being used to load relationships also.
By “this particular behavior” you mean applying the loadtimeout value to all read calls the function does behind the scene or the other way around?
You’ve set a timeout on that read action, which means it applies when being used to load relationships also.
Where was that set actually? What I set was only a custom read action with the read_action option and then I set the load timeout in the load call which I expected to be applied to that custom read call too.
with_timeout(:infinity, fn ->
# this timeout is where the error comes from
with_timeout(180000, fn ->
:timer.sleep(500000)
end)
end)
The related action used for the read has a timeout. Just because the outer action call has an infinite timeout, it still calls something with its own shorter timeout.
Ah, I see, but in that case, shouldn’t the inner call inherit the timeout of the outer call? Otherwise, what exactly is the point of the timeout option in a load call?
If you don’t mind, can you give me a more concrete example of these uses or link me to where they are described in the documentation? I’m not sure I understand exactly how to apply them.
use a different action
Why would using a different action helps here? :read_in_temp is already a custom action that is only used by this relationship.
In the action, set the timeout conditionally depending on something like context, and load with that, I.e load(foo: Ash.Query.set_timeout(...))
This would only works if the action itself is doing the load right? In my case I’m doing the load manually using Ash.load directly. Also, what if I need to load other inner relationships (load(foo: :bar)), in that case I would not be able to add the Ash.Query call right?
Use relationship context and switch on that in the destination action conditionally, i.e
What you mean here is add some field to the context like%{running_as_load?: true} and then add a prepare function that would catch that and set another timeout correct?
But this would not allow me to set the timeout value from “outside” the resource in the Ash.load call correct?
record |> Ash.load(similar_grantee_entity: fn query -> query end)
I get:
** (FunctionClauseError) no function clause matching in Ash.Resource.Info.attribute/2
The following arguments were given to Ash.Resource.Info.attribute/2:
# 1
Core.Pacman.Markets.Entity
# 2
#Function<42.18682967/1 in :erl_eval.expr/6>
Attempted function clauses (showing 1 out of 1):
def attribute(resource, name) when is_binary(name) or is_atom(name)
(ash 3.5.6) lib/ash/resource/info.ex:743: Ash.Resource.Info.attribute/2
(ash 3.5.6) lib/ash/query/query.ex:1737: Ash.Query.do_load/2
(elixir 1.18.1) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
(ash 3.5.6) lib/ash/query/query.ex:1544: anonymous fn/3 in Ash.Query.load/3
(elixir 1.18.1) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
(ash 3.5.6) lib/ash.ex:1900: Ash.load/3
(ash 3.5.6) lib/ash.ex:1864: Ash.load/3
iex:20: (file)
Which would make sense if I just look at the Ash.load typespec, but, at the same time, that makes me wonder how that test is working at all
Hey @zachdaniel just a quick bump since this still creates severe issues to our system
The only way that I think I can fix it now, if I understood correctly, is to create a custom read action where I set the timeout field of it in the action itself.
I guess that would work, but it seems like a very inflexible solution.
For example, let’s say I know that the read action will return a bunch of results instead of just a few, in this case, I need to have a very big timeout set to that action just because, sometimes, I need to fetch more data.
Same issue if I know that the db is under heavy load, since I can’t customize the timeout of the relationships when calling the action, my only solution is assume that the DB is always under load and set a default timeout that is pretty big which can be undesirable in some cases.
You did mention this:
But I still can’t understand how exactly I should use this as this doesn’t seem to be a valid call since set_timeout doesn’t exists and timeout requires a query as first argument.
I think I need to see a more comprehensive example of the actions and relationships at play. Where is the 180_000ms timeout coming from? How is it being set. I don’t think I’ve seen everything at play here yet?