Background
I have a Phoenix LiveView project that calls a dependency. Sometimes this call is fast, other times it takes up to a couple of minutes.
When the call is fast (lets say, 10 seconds) Phoenix recieves the answer and all my variables in assigns
are updated correctly.
However, for the case where the call to the external service takes a couple of minutes, the app freezes (which is expected since I am performing a call, which is blocking) and then when it resumes, nothing happens.
No error is shown, and none of my variables in assigns
are updated. This is very confusing. It will still happen, even when the call to the external service was successful.
Code
This is the code I have in my Phoenix project application.ex
:
def start(_type, _args) do
children = [
Telemetry,
{Phoenix.PubSub, name: WebInterface.PubSub},
Endpoint,
Manager #3rd party dependency
]
opts = [strategy: :one_for_one, name: WebInterface.Supervisor]
Supervisor.start_link(children, opts)
end
This is the default boilerplate auto-generated code with my 3rd party dependency Manager
added as a child.
Now, my Phoenix app calls Manager
, and inside of manager magic happens. This magic calls other GenServers
which then reply when the are done working.
Basically, when a user clicks a button, I call Manager.do_something()
which may or may not take quite a while.
Current Theory
My current theory here, knowing that Manager
does a Genserver.call
inside, is that some code in Phoenix, for some reason, decided that 2 minutes is too long and then times out.
This is supported by the fact that if I make the call to Manager
quick (by changing the code and returning a dummy value) then everything works as expected.
Questions
I am not familiar with Phoenix, so this means I am probably missing something:
- Is there a default timeout for genservers that I am not aware of?
- How can I change this behaviour, so my Phoenix app waits for the result and updates the
assigns
variable as expected?