* lib/net/imap.rb (Net::IMAP#initialize): Close the opened socket when
any exception occur. This fixes a fd leak by IMAPTest#test_imaps_post_connection_check which start_tls_session() raises an exception. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46210 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
02afafb42a
commit
cbd370f669
@ -1,3 +1,10 @@
|
|||||||
|
Wed May 28 19:00:31 2014 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* lib/net/imap.rb (Net::IMAP#initialize): Close the opened socket when
|
||||||
|
any exception occur.
|
||||||
|
This fixes a fd leak by IMAPTest#test_imaps_post_connection_check
|
||||||
|
which start_tls_session() raises an exception.
|
||||||
|
|
||||||
Wed May 28 18:06:13 2014 Tanaka Akira <akr@fsij.org>
|
Wed May 28 18:06:13 2014 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* ext/openssl/ossl_ssl.c (ossl_ssl_close): Fix sync_close to work
|
* ext/openssl/ossl_ssl.c (ossl_ssl_close): Fix sync_close to work
|
||||||
|
@ -1043,40 +1043,43 @@ module Net
|
|||||||
@tagno = 0
|
@tagno = 0
|
||||||
@parser = ResponseParser.new
|
@parser = ResponseParser.new
|
||||||
@sock = TCPSocket.open(@host, @port)
|
@sock = TCPSocket.open(@host, @port)
|
||||||
if options[:ssl]
|
begin
|
||||||
start_tls_session(options[:ssl])
|
if options[:ssl]
|
||||||
@usessl = true
|
start_tls_session(options[:ssl])
|
||||||
else
|
@usessl = true
|
||||||
@usessl = false
|
else
|
||||||
end
|
@usessl = false
|
||||||
@responses = Hash.new([].freeze)
|
|
||||||
@tagged_responses = {}
|
|
||||||
@response_handlers = []
|
|
||||||
@tagged_response_arrival = new_cond
|
|
||||||
@continuation_request_arrival = new_cond
|
|
||||||
@idle_done_cond = nil
|
|
||||||
@logout_command_tag = nil
|
|
||||||
@debug_output_bol = true
|
|
||||||
@exception = nil
|
|
||||||
|
|
||||||
@greeting = get_response
|
|
||||||
if @greeting.nil?
|
|
||||||
@sock.close
|
|
||||||
raise Error, "connection closed"
|
|
||||||
end
|
|
||||||
if @greeting.name == "BYE"
|
|
||||||
@sock.close
|
|
||||||
raise ByeResponseError, @greeting
|
|
||||||
end
|
|
||||||
|
|
||||||
@client_thread = Thread.current
|
|
||||||
@receiver_thread = Thread.start {
|
|
||||||
begin
|
|
||||||
receive_responses
|
|
||||||
rescue Exception
|
|
||||||
end
|
end
|
||||||
}
|
@responses = Hash.new([].freeze)
|
||||||
@receiver_thread_terminating = false
|
@tagged_responses = {}
|
||||||
|
@response_handlers = []
|
||||||
|
@tagged_response_arrival = new_cond
|
||||||
|
@continuation_request_arrival = new_cond
|
||||||
|
@idle_done_cond = nil
|
||||||
|
@logout_command_tag = nil
|
||||||
|
@debug_output_bol = true
|
||||||
|
@exception = nil
|
||||||
|
|
||||||
|
@greeting = get_response
|
||||||
|
if @greeting.nil?
|
||||||
|
raise Error, "connection closed"
|
||||||
|
end
|
||||||
|
if @greeting.name == "BYE"
|
||||||
|
raise ByeResponseError, @greeting
|
||||||
|
end
|
||||||
|
|
||||||
|
@client_thread = Thread.current
|
||||||
|
@receiver_thread = Thread.start {
|
||||||
|
begin
|
||||||
|
receive_responses
|
||||||
|
rescue Exception
|
||||||
|
end
|
||||||
|
}
|
||||||
|
@receiver_thread_terminating = false
|
||||||
|
rescue Exception
|
||||||
|
@sock.close
|
||||||
|
raise
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def receive_responses
|
def receive_responses
|
||||||
|
@ -505,19 +505,20 @@ class IMAPTest < Test::Unit::TestCase
|
|||||||
ths = Thread.start do
|
ths = Thread.start do
|
||||||
begin
|
begin
|
||||||
sock = server.accept
|
sock = server.accept
|
||||||
sock.print("* OK test server\r\n")
|
|
||||||
sock.gets
|
|
||||||
sock.print("RUBY0001 OK completed\r\n")
|
|
||||||
ctx = OpenSSL::SSL::SSLContext.new
|
|
||||||
ctx.ca_file = CA_FILE
|
|
||||||
ctx.key = File.open(SERVER_KEY) { |f|
|
|
||||||
OpenSSL::PKey::RSA.new(f)
|
|
||||||
}
|
|
||||||
ctx.cert = File.open(SERVER_CERT) { |f|
|
|
||||||
OpenSSL::X509::Certificate.new(f)
|
|
||||||
}
|
|
||||||
sock = OpenSSL::SSL::SSLSocket.new(sock, ctx)
|
|
||||||
begin
|
begin
|
||||||
|
sock.print("* OK test server\r\n")
|
||||||
|
sock.gets
|
||||||
|
sock.print("RUBY0001 OK completed\r\n")
|
||||||
|
ctx = OpenSSL::SSL::SSLContext.new
|
||||||
|
ctx.ca_file = CA_FILE
|
||||||
|
ctx.key = File.open(SERVER_KEY) { |f|
|
||||||
|
OpenSSL::PKey::RSA.new(f)
|
||||||
|
}
|
||||||
|
ctx.cert = File.open(SERVER_CERT) { |f|
|
||||||
|
OpenSSL::X509::Certificate.new(f)
|
||||||
|
}
|
||||||
|
sock = OpenSSL::SSL::SSLSocket.new(sock, ctx)
|
||||||
|
sock.sync_close = true
|
||||||
sock.accept
|
sock.accept
|
||||||
sock.gets
|
sock.gets
|
||||||
sock.print("* BYE terminating connection\r\n")
|
sock.print("* BYE terminating connection\r\n")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user