Skip to content

Commit e401c03

Browse files
committed
avoid using ensure in Net::SFTP.start to prevent hangs when exceptions are raised
1 parent bc755d3 commit e401c03

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

CHANGELOG.rdoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
=== (unreleased)
2+
3+
* Avoid using 'ensure' in Net::SFTP.start since it causes unfriendly behavior when exceptions are raised [Jamis Buck]
4+
5+
16
=== 2.0.1 / 29 May 2008
27

38
* Open files in binary mode to appease Windows [Jamis Buck]

Rakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ Echoe.new('net-sftp', version) do |p|
2121
p.summary = "A pure Ruby implementation of the SFTP client protocol"
2222
p.url = "http://net-ssh.rubyforge.org/sftp"
2323

24-
p.dependencies = ["net-ssh >=1.99.1"]
24+
p.dependencies = ["net-ssh >=2.0.9"]
2525

2626
p.need_zip = true
2727
p.include_rakefile = true
2828

2929
p.rdoc_pattern = /^(lib|README.rdoc|CHANGELOG.rdoc)/
30-
end
30+
end

lib/net/sftp.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,21 @@ def self.start(host, user, options={}, &block)
3131
session = Net::SSH.start(host, user, options)
3232
sftp = Net::SFTP::Session.new(session, &block).connect!
3333

34-
sftp.loop if block_given?
34+
if block_given?
35+
sftp.loop
36+
session.close
37+
return nil
38+
end
3539

3640
sftp
37-
ensure
38-
session.close if session && block_given?
41+
rescue Exception => anything
42+
begin
43+
session.terminate!
44+
rescue Exception
45+
# swallow exceptions that occur while trying to shutdown
46+
end
47+
48+
raise anything
3949
end
4050
end
4151

@@ -57,4 +67,4 @@ def sftp(wait=true)
5767
sftp
5868
end
5969
end
60-
end
70+
end

0 commit comments

Comments
 (0)