pgapp
pgapp copied to clipboard
pgapp_worker does not check the source of handle_info({'EXIT',
Problem
pgapp_worker
expects to have one child epgsql_sock
which is the connection to the database. The function handle_info({'EXIT', From, Reason}, State)
deals with the case when this child dies for some reason. In this case we cast reconnect and a new child epgsql_sock
is created.
When using pgapp:with_transaction
, the code inside the provided function is run by the pgapp_worker
process. If the code inside the transaction function receives the message {'EXIT', From, Reason}
(for example a spawn_link
ed process finishes normally) pgapp_worker
will interpret this as a crash of its child epgsql_sock
and it will trigger a cast to reconnect
, even though the original epqgsql_sock
is alive and well.
This process will cause the number of open epgsql_sock
s to increase forever until the database limit is reached, at which point some of the open connections will be forcefully closed.
Solution
The function handle_info({'EXIT', From, Reason}, State)
should ensure that the From
PID is the same as its child epgsql_sock
. If it is not, then it should not attempt to reconnect.
I have a fix for this issue in progress, I will submit a PR tomorrow if all is well.
PR #27 seems to fix this, I will double check with a full test in the rest of the application code to make sure there is nothing I have missed.
I have tested and all looks good to me! Feel free to merge #27 at your convenience.