[ruby-core:32939] [Backport187-Backport#3999][Open] imap connection thread stuck on wait call

From: Karl Baum <redmine@...>
Date: 2010-10-28 15:55:46 UTC
List: ruby-core #32939
Backport #3999: imap connection thread stuck on wait call
http://redmine.ruby-lang.org/issues/show/3999

Author: Karl Baum
Status: Open, Priority: Normal

My ruby application is making many connections to imap servers and after about a day or so of running, all 200 worker threads deadlock on @response_arrival.wait within imap.rb:

    def get_tagged_response(tag)
      until @tagged_responses.key?(tag)
        @response_arrival.wait
      end
      return pick_up_tagged_response(tag)
    end

I looked at the code and the following lines look suspicious to me:

def receive_responses
      while true
        begin
          resp = get_response
        rescue Exception
          @sock.close
          @client_thread.raise($!)
          break
        end
        break unless resp
        begin
          synchronize do
            case resp
            when TaggedResponse
              @tagged_responses[resp.tag] = resp
              @response_arrival.broadcast
              if resp.tag == @logout_command_tag
                return
              end
            when UntaggedResponse
              record_response(resp.name, resp.data)
              if resp.data.instance_of?(ResponseText) &&
                  (code = resp.data.code)
                record_response(code.name, code.data)
              end
              if resp.name == "BYE" && @logout_command_tag.nil?
                @sock.close
                raise ByeResponseError, resp.raw_data
              end
            when ContinuationRequest
              @continuation_request = resp
              @response_arrival.broadcast
            end
            @response_handlers.each do |handler|
              handler.call(resp)
            end
          end
        rescue Exception
          @client_thread.raise($!)
        end
      end
    end

It looks like in the conditions of "when UntaggedResponse", the @response_arrival.broadcast is not invoked.  Would this cause the waiting thread to wait forever? 

thx


----------------------------------------
http://redmine.ruby-lang.org

In This Thread

Prev Next