It's bad form to block a gen_server like this - prevents lots of useful things from working correctly. Would be better to send a message to reconnect after a time. Unfortunately that will require a more code to handle messages when you are not connected - would have to store them in a list and then resend when connected.