Ash doesn't seem to use the action call timeout value when loading relationships

I have an action in my entity resource that is written like this:

    read :all_stale do
      description "Returns all entities that are stale"
      pagination keyset?: true

      filter expr(status == :stale)

      prepare build(
                load: [
                  grantee_records: :property_by_rebuilt_id,
                  grantor_records: :property_by_rebuilt_id
                ],
                sort: :id
              )
    end

To call it, I run this code:

    Entity
    |> Ash.Query.for_read(:all_stale, %{})
    |> Markets.stream!(batch_size: @chunk_size, timeout: :infinity)
    ...

As you can see, I’m passing timeout: :infinity to the Markets.stream!/2 call. I expected that this timeout would be also used on any “internal” load the action needs to do, but that is not what happens and I end up having this error when Ash tries to load property_by_rebuilt_id:

** (Ash.Error.Invalid) Input Invalid

* Core.Pacman.Markets.Property.read timed out after 180000ms.

The default timeout can be configured on the api,

    execution do
      timeout :timer.seconds(60)
    end

Each request can be configured with a timeout via `Ash.Changeset.timeout/2` or `Ash.Query.timeout/2`.

    at grantor_records, property_by_rebuilt_id
  (elixir 1.16.3) lib/process.ex:860: Process.info/2
  (ash 2.20.3) lib/ash/error/exception.ex:59: Ash.Error.Invalid.Timeout.exception/1
  (ash 2.20.3) lib/ash/engine/engine.ex:162: Ash.Engine.task_with_timeout/5
  (ash 2.20.3) lib/ash/actions/read/read.ex:537: Ash.Actions.Read.maybe_in_transaction/3
  (ash 2.20.3) lib/ash/actions/read/read.ex:216: Ash.Actions.Read.do_run/3
  (ash 2.20.3) lib/ash/actions/read/read.ex:49: anonymous fn/3 in Ash.Actions.Read.run/3
  (ash 2.20.3) lib/ash/actions/read/read.ex:48: Ash.Actions.Read.run/3
  (ash 2.20.3) lib/ash/actions/read/relationships.ex:333: anonymous fn/2 in Ash.Actions.Read.Relationships.do_fetch_related_records/3
  (ash 2.20.3) lib/ash/engine/engine.ex:514: anonymous fn/4 in Ash.Engine.async/2
  (elixir 1.16.3) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2
  (elixir 1.16.3) lib/task/supervised.ex:36: Task.Supervised.reply/4
    (elixir 1.16.3) lib/process.ex:860: Process.info/2
    (ash 2.20.3) lib/ash/error/exception.ex:59: Ash.Error.Invalid.exception/1
    (ash 2.20.3) lib/ash/error/error.ex:600: Ash.Error.choose_error/2
    (ash 2.20.3) lib/ash/error/error.ex:260: Ash.Error.to_error_class/2
    (ash 2.20.3) lib/ash/actions/read/read.ex:281: Ash.Actions.Read.do_run/3
    (ash 2.20.3) lib/ash/actions/read/read.ex:49: anonymous fn/3 in Ash.Actions.Read.run/3
    (ash 2.20.3) lib/ash/actions/read/read.ex:48: Ash.Actions.Read.run/3
    (ash 2.20.3) lib/ash/actions/read/relationships.ex:333: anonymous fn/2 in Ash.Actions.Read.Relationships.do_fetch_related_records/3
    (ash 2.20.3) lib/ash/engine/engine.ex:514: anonymous fn/4 in Ash.Engine.async/2
    (elixir 1.16.3) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2
    (elixir 1.16.3) lib/task/supervised.ex:36: Task.Supervised.reply/4

Unfortunately, this is Ash 2.20.3, not Ash 3, not sure if the same issue happens in Ash 3.

I believe that the issue of it potentially being ignored is fixed in 3.0, but calls to nested actions do not inherit the timeout of the parent call, so if you call other actions you’d have to set a timeout there as well.

1 Like

Hey @zachdaniel , so, now that my project is in Ash 3, I am able to test it out and I still seeing the same issue.

Seems like even on Ash 3 the timeout set in the Ash.stream call is being ignored by when loading the resource relationships, and, because of that, giving me a timeout error.

Thats a shame. Would you be able to potentially reproduce this?