Why does this code deadlock?

B

Bill Kelly

Hi,

I'm getting a deadlock on this small program, on both Windows
and Linux:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
require 'net/ftp'
Thread.abort_on_exception = true
ftp = Net::FTP.new('ftp.idsoftware.com')
p( Thread.new {$SAFE=4; ftp.login('anonymous', '(e-mail address removed)')}.value )

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


# ruby -v ftp_safe_test.rb
ruby 1.8.4 (2005-12-24) [i386-mswin32]
ftp_safe_test.rb:4:in `value': Thread(0x27855c8): deadlock (fatal)
from ftp_safe_test.rb:4


$ ruby -v safe_ftp_test.rb
ruby 1.8.4 (2005-12-24) [i686-linux]
safe_ftp_test.rb:4:in `value': Thread(0x4f060748): deadlock (fatal)
from safe_ftp_test.rb:4


Now, I didn't necessarily expect the code to WORK at $SAFE=4,
but I was anticipating a SecurityError rather than a deadlock.

(I've tried it with Thread.abort_on_exception both true and
false, same result.)

Any thoughts?

Thanks,

Regards,

Bill
 
E

Ezra Zygmuntowicz

Hi Bill-

Hi,

I'm getting a deadlock on this small program, on both Windows
and Linux:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
require 'net/ftp'
Thread.abort_on_exception = true
ftp = Net::FTP.new('ftp.idsoftware.com')
p( Thread.new {$SAFE=4; ftp.login('anonymous', '(e-mail address removed)')}.value )

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


# ruby -v ftp_safe_test.rb
ruby 1.8.4 (2005-12-24) [i386-mswin32]
ftp_safe_test.rb:4:in `value': Thread(0x27855c8): deadlock (fatal)
from ftp_safe_test.rb:4


$ ruby -v safe_ftp_test.rb
ruby 1.8.4 (2005-12-24) [i686-linux]
safe_ftp_test.rb:4:in `value': Thread(0x4f060748): deadlock (fatal)
from safe_ftp_test.rb:4


Now, I didn't necessarily expect the code to WORK at $SAFE=4,
but I was anticipating a SecurityError rather than a deadlock.

(I've tried it with Thread.abort_on_exception both true and
false, same result.)

Any thoughts?

Thanks,

Regards,

Bill

Are you using ruby 1.8.6 by chance? If so install the laets
fastthread gem and require it in your script to see if it fixes the
deadlock. Unfortunately the fastthread code in the ruby1.8.6 release
has some bugs that are fixed in the fastthread gem

Cheers-
-- Ezra Zygmuntowicz
-- Lead Rails Evangelist
-- (e-mail address removed)
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)
 
B

Bill Kelly

Hi Ezra,
I'm getting a deadlock on this small program, on both Windows
and Linux:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
require 'net/ftp'
Thread.abort_on_exception = true
ftp = Net::FTP.new('ftp.idsoftware.com')
p( Thread.new {$SAFE=4; ftp.login('anonymous', '(e-mail address removed)')}.value )

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# ruby -v ftp_safe_test.rb
ruby 1.8.4 (2005-12-24) [i386-mswin32]
ftp_safe_test.rb:4:in `value': Thread(0x27855c8): deadlock (fatal)
from ftp_safe_test.rb:4

$ ruby -v safe_ftp_test.rb
ruby 1.8.4 (2005-12-24) [i686-linux]
safe_ftp_test.rb:4:in `value': Thread(0x4f060748): deadlock (fatal)
from safe_ftp_test.rb:4


Now, I didn't necessarily expect the code to WORK at $SAFE=4,
but I was anticipating a SecurityError rather than a deadlock.

(I've tried it with Thread.abort_on_exception both true and
false, same result.)

Are you using ruby 1.8.6 by chance? If so install the laets
fastthread gem and require it in your script to see if it fixes the
deadlock. Unfortunately the fastthread code in the ruby1.8.6 release
has some bugs that are fixed in the fastthread gem

The above was 1.8.4 with the standard thread.rb.

Trying ruby 1.8.6 (2007-03-16 patchlevel 3) [i686-linux]
...I still get the deadlock, with or without fastthread:

ruby -v ftp_safe_test.rb
ruby 1.8.6 (2007-03-16 patchlevel 3) [i686-linux]
ftp_safe_test.rb:5:in `value': Thread(0x50df1704): deadlock (fatal)
from ftp_safe_test.rb:5


Regards,

Bill
 
N

Nobuyoshi Nakada

Hi,

At Wed, 18 Apr 2007 08:34:03 +0900,
Bill Kelly wrote in [ruby-talk:248300]:
require 'net/ftp'
Thread.abort_on_exception = true
ftp = Net::FTP.new('ftp.idsoftware.com')
th = Thread.new {$SAFE=4; ftp.login('anonymous', '(e-mail address removed)')}
Thread.critical = false
p th.value
 
B

Bill Kelly

From: "Nobuyoshi Nakada said:
At Wed, 18 Apr 2007 08:34:03 +0900,
Bill Kelly wrote in [ruby-talk:248300]:
require 'net/ftp'
Thread.abort_on_exception = true
ftp = Net::FTP.new('ftp.idsoftware.com')
th = Thread.new {$SAFE=4; ftp.login('anonymous', '(e-mail address removed)')}
Thread.critical = false
p th.value

Nobu, you RULE!!! :D


Thanks!

Bill
 
N

Nobuyoshi Nakada

Hi,

At Wed, 18 Apr 2007 16:53:25 +0900,
Yukihiro Matsumoto wrote in [ruby-talk:248325]:
|At Wed, 18 Apr 2007 08:34:03 +0900,
|Bill Kelly wrote in [ruby-talk:248300]:
|> require 'net/ftp'
|> Thread.abort_on_exception = true
|> ftp = Net::FTP.new('ftp.idsoftware.com')
| th = Thread.new {$SAFE=4; ftp.login('anonymous', '(e-mail address removed)')}
| Thread.critical = false
| p th.value

Who set Thread.critical? It should be fixed, I think.

mon_acquire called from mon_enter fails because of
SecurityError, and leaves Thread.critical true.


Index: lib/monitor.rb
===================================================================
--- lib/monitor.rb (revision 12191)
+++ lib/monitor.rb (working copy)
@@ -106,12 +106,15 @@ def wait(timeout = nil)
ensure
Thread.critical = true
- if timer && timer.alive?
- Thread.kill(timer)
+ begin
+ if timer && timer.alive?
+ Thread.kill(timer)
+ end
+ if @waiters.include?(Thread.current) # interrupted?
+ @waiters.delete(Thread.current)
+ end
+ @monitor.instance_eval {mon_enter_for_cond(count)}
+ ensure
+ Thread.critical = false
end
- if @waiters.include?(Thread.current) # interrupted?
- @waiters.delete(Thread.current)
- end
- @monitor.instance_eval {mon_enter_for_cond(count)}
- Thread.critical = false
end
end
@@ -211,4 +214,5 @@ def mon_enter
mon_acquire(@mon_entering_queue)
@mon_count += 1
+ ensure
Thread.critical = false
end
@@ -300,6 +304,7 @@ def mon_exit_for_cond
count = @mon_count
@mon_count = 0
- mon_release
return count
+ ensure
+ mon_release
end
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top