Project

General

Profile

Actions

Bug #14051

closed

net/imap issue on idle method with an empty block

Added by simayosi (SHIMAYOSHI Takao) over 6 years ago. Updated over 4 years ago.

Status:
Closed
Target version:
-
[ruby-core:83554]

Description

Description
If Net::IMAP#idle method is called with empty block, all response handlers that have added beforehand are unintentionally removed before returning from the call.

Sample Code
imap.add_response_handler do |resp|
if resp.kind_of?(Net::IMAP::UntaggedResponse) and resp.name == "EXISTS"
imap.idle_done
end
end
imap.idle {}

the response handler firstly added is unregistered here

Cause
@response_handlers.delete(nil) is executed in Net::IMAP#remove_response_handler called from the idle method.

Updated by shugo (Shugo Maeda) over 6 years ago

  • Status changed from Open to Assigned
  • Assignee set to shugo (Shugo Maeda)

Updated by shugo (Shugo Maeda) over 6 years ago

simayosi (SHIMAYOSHI Takao) wrote:

Description
If Net::IMAP#idle method is called with empty block, all response handlers that have added beforehand are unintentionally removed before returning from the call.

Sample Code
imap.add_response_handler do |resp|
if resp.kind_of?(Net::IMAP::UntaggedResponse) and resp.name == "EXISTS"
imap.idle_done
end
end
imap.idle {}

the response handler firstly added is unregistered here

I couldn't reproduce the problem with the following code:

imap.add_response_handler do |resp|
  if resp.kind_of?(Net::IMAP::UntaggedResponse) and resp.name == "EXISTS"
    imap.idle_done
  end
end
p imap.response_handlers #=> [#<Proc:0x0000560887b7b958@t.rb:8>]
imap.idle {}
p imap.response_handlers #=> [#<Proc:0x0000560887b7b958@t.rb:8>]

Cause
@response_handlers.delete(nil) is executed in Net::IMAP#remove_response_handler called from the idle method.

Even if the body of a block is empty, a block parameter cannot be nil.

def foo(&b)
  p b
end
foo {} #=> #<Proc:0x00005595c4e7f298@(irb):2>

And even if no block is given, a LocalJumpError will be raised.

    def idle(timeout = nil, &response_handler)
      raise LocalJumpError, "no block given" unless response_handler
Actions #3

Updated by jeremyevans0 (Jeremy Evans) over 4 years ago

  • Status changed from Assigned to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0