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

only reconnect if we receive EXIT from the conn pid #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aktungmak
Copy link

No description provided.

@aktungmak aktungmak force-pushed the pgapp-worker-check-source-of-exit branch from c5803cf to 4d6ebbf Compare December 14, 2018 11:35
[self(), Conn, Reason, NewDelay]),
{noreply, State#state{conn = undefined, delay = NewDelay, timer = Tref}};

handle_info(_Other, State) ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want that extra clause?

@aktungmak
Copy link
Author

If we don't have that clause, then the worker will crash any time it receives a message other than the 'EXIT' from epgsql_sock. When using pgapp:with_transaction this can occur since the transaction function is run by the worker process.

@davidw
Copy link
Member

davidw commented Dec 17, 2018

@aktungmak is there a way to trigger that that always works, so I can test it out?

I do not like 'catch all' handlers, as they may let problems sneak in.

Thanks!

@aktungmak
Copy link
Author

I didn't get a chance to write some proper example code to reproduce it, but essentially this is how the issue is triggered:

pgapp:with_transaction(fun() -> self() ! {'EXIT', self(), normal} end)

@davidw
Copy link
Member

davidw commented Dec 18, 2018

@aktungmak ok... that works. What kind of real world code was causing something like that?

@aktungmak
Copy link
Author

The code was using a library that was spawn_linking other processes which then finished normally, and since the pgapp_worker process is trapping exits it was receiving {'EXIT', Pid, normal} messages. I wrote a bit more detail on this in issue #26.

@davidw
Copy link
Member

davidw commented Jan 4, 2019

Would it make sense to do something like wrap the other library with a receive looking for its exit?

@aktungmak
Copy link
Author

We have refactored the code that was using the other library to perform the work outside the transaction now, which avoid the issue in this particular case.

@davidw
Copy link
Member

davidw commented Jan 7, 2019

@aktungmak would your refactoring still work if we include your patch, without the 'catchall' handle_info ?

@aktungmak
Copy link
Author

Yep, that will be just fine 👍

@aktungmak
Copy link
Author

The only problem will be as I mentioned above, that the worker will crash if it receives any other messages inside the transaction function (eg if a spawn_linked process finishes normally).

We are no longer doing that so its OK by me but it is good to know in future that the transaction functions should avoid doing that.

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

Successfully merging this pull request may close these issues.

2 participants