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

Don't exit when a connection fails and adds Paddle.reconnect/1 #21

Merged
merged 10 commits into from
Aug 12, 2018

Conversation

shamanime
Copy link
Contributor

This PR is a complement to #20.

It still needs improvements but the code works.

When starting Paddle, if the connection fails it will hold :not_connected as the state and will reply {:error, :not_connected} for messages it receives.

Paddle.reconnect/1 was added, it will reconnect using the connection options received as argument or fetch the options from the config.

@minijackson
Copy link
Owner

This looks great! Thank you so much!

Nitpicks:

  • It could be nice to know why the connection would fail. How about the do_connect returns the Reason from :eldap.open (as the init and reconnect would, then), but keep the :not_connected as the GenServer state?
  • I think some specs needs to be updated. I don't mind doing it, the :eldap doc doesn't seem to enumerate the different failures. I'll look at the code but if I remember correctly, it's a combination of LDAP specific errors and :gen_tcp's connect errors

Great job! I think that puts us closer to supporting multiple LDAP servers and multiple connections (#4).

@shamanime
Copy link
Contributor Author

shamanime commented Jul 26, 2018 via email

@minijackson
Copy link
Owner

This should help with the specs

Change the state from :not_connected to {:not_connected, reason}.

This allows us to be able to decide on trying a reconnection pattern matching on the reason.
@shamanime
Copy link
Contributor Author

Had a little time to improve the state. What do you say?

Now just need to work on the specs. Will give your link a good read next week!

@minijackson
Copy link
Owner

I re-read :eldap's code and apparently, :eldap.open does not return any meaningful error x) But let's keep it that way in case it changes (and I hope it will).

I see you're keeping the error around and reply that to subsequent calls. That could be useful, but I'm afraid it could give the wrong idea, and make people think it tries to reconnect each time :-/

My initial thought was that only init and reconnect would return the error from :eldap.open and the rest would just return {:error, :not_connected}

What's your take on that? Am I missing something?

@shamanime
Copy link
Contributor Author

No, you're not missing anything. What you said makes sense.

I think we should be good now. I may have overlooked the specs but seems like the only needed change was the spec for ldap_conn, which now holds a pid or {:not_connected, reason}.

@shamanime shamanime mentioned this pull request Aug 9, 2018
@minijackson
Copy link
Owner

Awesome!

Could do you just convert :eldap.open's error to a String (probably inside do_connect) and adapt ldap_conn's type accordingly? After that, it will be perfect for merging.

@shamanime
Copy link
Contributor Author

Done!

@minijackson minijackson merged commit aa9370b into minijackson:master Aug 12, 2018
@minijackson
Copy link
Owner

Perfect! Many thanks

@shamanime
Copy link
Contributor Author

Thank YOU for working so patiently with me on this!

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