cinchrb / cinch

The IRC Bot Building Framework
http://www.rubydoc.info/gems/cinch
MIT License
1k stars 180 forks source link

PluginList#unregister_all does not unregister all plugins #111

Closed vivien closed 11 years ago

vivien commented 11 years ago

With @fridim, we've noticed that #unregister_all doesn't work. Here's how to reproduce it, with the following bot:

require 'cinch'

class Hashtag
  include Cinch::Plugin

  listen_to :channel

  def listen(m)
    hashtags = m.message.scan(/\B#\w*[a-zA-Z]+\w*/)
    unless hashtags.empty?
      m.reply "list of tags: #{ hashtags.join(', ') }!"
    end
  end
end

trap "SIGUSR1" do
  $bot.plugins.register_plugin(Hashtag)
end

trap "SIGUSR2" do
  $bot.plugins.unregister_all
end

$bot = Cinch::Bot.new do
  configure do |c|
    c.nick = "test-unregister-all"
    c.server = "irc.freenode.org"
    c.channels = ["#cinch-bots"]
    c.plugins.plugins = []
  end
end

$bot.start

You can try:

# add new instances of the Hashtag plugin
pkill -SIGUSR1 ruby
pkill -SIGUSR1 ruby
pkill -SIGUSR1 ruby

Then write "foo #bar" in the channel. The bot will parse your message 3 times. Then unregister with:

# should unregister all plugins
pkill -SIGUSR2 ruby

The previous message will still be parsed, by at least 1 handler.

Ruby 1.9.3 / Cinch 2.0.3

fridim commented 11 years ago

I confirm this bug. (In the @v0n report, don't look at the Hashtag plugin, it's just an example : you can reproduce this bug with a simple "pong!" plugin.)

I temporarly fix this bug on user-side with :

until @bot.plugins.empty? do
  @bot.plugins.unregister_all
end

Regards, fridim

dominikh commented 11 years ago

For the record: Adding plugins dynamically wasn't the issue. It would've occurred with more than one statically loaded plugin as well. See the commit message for more information.

Thanks for reporting this issue, thanks fridim for confirming it.