Detect pid reuse
Thu Jul 9 09:26:43 CEST 2020
On 2020-07-06 14:09, Dinislam Salikhov wrote:
> If I want to send a command to the database, I search for the pid of
> the corresponding connection (in supervisor's children list). And
Perhaps register the processes with a name so that instead of searching
for a literal pid, which may indeed change and requires more bookkeeping
in your application code, you lookup the relevant connect by a name in a
process registry. Should the old connection go away, the new one takes
over the same name.
If you have multiple connections to any given db (a pool of pools, if
you will), using a process group module like pg makes this easy.
Even then, you'll obviously need to handle the failure case of the
process exiting between the message being sent and the response being
received, but at least the lookup will be consistent.
More information about the erlang-questions