[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Why does this code deadlock?

Bill Kelly

4/17/2007 11:34:00 PM

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', 'abc@def.com')}.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



4 Answers

Ezra Zygmuntowicz

4/18/2007 3:05:00 AM

0

Hi Bill-

On Apr 17, 2007, at 4:34 PM, Bill Kelly wrote:

> 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', 'abc@def.com')}.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
-- ez@engineyard.com
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)



Bill Kelly

4/18/2007 6:02:00 AM

0

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', 'abc@def.com')}.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



Nobuyoshi Nakada

4/18/2007 7:22:00 AM

0

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', 'abc@def.com')}
Thread.critical = false
p th.value

--
Nobu Nakada

Bill Kelly

4/18/2007 7:31:00 AM

0

From: "Nobuyoshi Nakada" <nobu@ruby-lang.org>
>
> 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', 'abc@def.com')}
> Thread.critical = false
> p th.value

Nobu, you RULE!!! :D


Thanks!

Bill