Setting the timeout value in my
GenServer calls was always something that I found uncomfortable, it seemed to me that 5 seconds default was kinda a “random” number and I was not sure what number I needed to use.
At the same time, I was scared of using
:infinity for it since you rarely see an example using it, so I thought it was not safe (I thought you would be stuck if the callee died or something like that).
Well, looking deeply I found this link Thoughts on when to use ‘infinity’ timeouts for gen_server:call and friends. They do discuss the call default timeout and says that it should be
:infinity by default.
After that, I did some tests and indeed it seems to me to be very safe to use it as the default (and only use a timed timeout when it really makes sense). It fixed a lot of issues I had with timeouts when I changed the backend machine processing power which would often trigger these timeouts.
So, my question is a two-part one (sorry for that), the first part is, what is your opinion about that? Maybe Genserver documentation should be more clear about it (If it is I couldn’t find it sincerely)? Maybe we should have
:infinity as the default timeout for calls as the link suggests?
The second part of the question is in regard of other timeouts configurations in the system that too are not really clear if they are safe to use
:infinity or not.
Ecto.Repo, you have the
:timeout parameter for your config, this is what the documentation tells about it:
The time in milliseconds to wait for the query call to finish.
:infinitywill wait indefinitely (default: 15000)
As you can see, it mentions
:infinity, but it is not clear (at least to me) if the
query call is a
Genserver.call or it is the call to the database server. If it is the first, I would consider safe to use
:infinity since if the callee dies, we will not be stuck. But if it is referencing the database server, then my guess is that it could simply crash/disappear/whatever and it would never return from it, basically being locked in this call forever.
So, the second part of my question is, is it safe to use
:infinity for the case of
Ecto.Repo as an example? Do you know other libs that would not be?
Thank you very much.