Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pgapp_worker does not check the source of handle_info({'EXIT', #26

Open
aktungmak opened this issue Dec 13, 2018 · 3 comments
Open

pgapp_worker does not check the source of handle_info({'EXIT', #26

aktungmak opened this issue Dec 13, 2018 · 3 comments

Comments

@aktungmak
Copy link

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_linked 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_socks 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.

@aktungmak
Copy link
Author

I have a fix for this issue in progress, I will submit a PR tomorrow if all is well.

@aktungmak
Copy link
Author

aktungmak commented Dec 14, 2018

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.

@aktungmak
Copy link
Author

I have tested and all looks good to me! Feel free to merge #27 at your convenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant