hedwig-im / hedwig

An Adapter-based Bot Framework for Elixir Applications
MIT License
650 stars 73 forks source link

Reconnect does not work #79

Closed PhillippOhlandt closed 6 years ago

PhillippOhlandt commented 6 years ago

Hey,

I am using Hedwig with the IRC adapter on a Slack channel. I noticed that Slack sometimes sends a :disconnected message which is unhandled. So I extended the IRC adapter with the following function:

  def handle_info(:disconnected, state = {robot, _opts, _client}) do
    Hedwig.Robot.handle_disconnect(robot, nil)
    {:noreply, state}
  end

And my robot module contains:

  def handle_disconnect(_reason, state) do
    IO.puts "handle disconnect"
    {:reconnect, 5000, state}
  end

So when I start the bot with a slightly wrong configuration (so Slack disconnects me right away) I get the following:

12:27:31.190 [debug] Unknown message: {:unrecognized, "004", %IrcMessage{args: ["phillipp", "IRC-SLACK gateway"], cmd: "004", ctcp: false, host: [], nick: [], server: "irc.tinyspeck.com", user: []}}

12:27:36.183 [debug] Unknown message: {:received, "SSL connection required", %ExIrc.SenderInfo{host: [], nick: "slackbot", user: []}}

12:27:36.184 [debug] Unknown message: {:unrecognized, "444", %IrcMessage{args: ["phillipp", "SSL connection required"], cmd: "444", ctcp: false, host: [], nick: [], server: [], user: []}}
handle disconnect

12:27:36.190 [info]  'Connection to elixir-lang.irc.slack.com:6667 closed!'

As you can see, my handle_disconnect/2 function gets called but the bot itself does not reconnect.

PhillippOhlandt commented 6 years ago

Short workaround is to just let it crash™.

  def handle_disconnect(_reason, state) do
    raise Foo
    {:reconnect, 5000, state}
  end
scrogson commented 6 years ago

@PhillippOhlandt it appears that the IRC adapter is not up-to-date with Hedwig 1.0. It's still using rc.3. It's possible that it isn't handling those messages properly.

PhillippOhlandt commented 6 years ago

@scrogson Ah that could explain it. Unfortunately, I don't think the maintainer will update it anytime soon. I think about cloning it and making a special version for the Slack IRC Bridge.

BTW, how is Hedwig 2.0 going? I saw the PR.

scrogson commented 6 years ago

@PhillippOhlandt I work with the author...I'll ask if he wouldn't mind updating it.

As for 2.0...I haven't had much time to work on it recently. But now that you're asking...I might try to find time to finish up that PR soon :wink:

PhillippOhlandt commented 6 years ago

No pressure, everything works fine right now (even with the reconnect workaround) :)

scrogson commented 6 years ago

@PhillippOhlandt can we call this closed then?

PhillippOhlandt commented 6 years ago

@scrogson I think so since this needs to be fixed in the adapter (if not already).