[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

socket 10s hangs

Roger Pack

8/27/2007 8:22:00 PM

Question: anybody ever had the situation of a socket create or send that
freezes all thread for multiples of 10s? (i.e. 10 or 20 or
30--exactly?) Odd, isn't it? Thanks! [note this is tcp sockets to IP
addresses, not hostnames, so it is most likely not a DNS latency]
-Roger
--
Posted via http://www.ruby-....

7 Answers

Joel VanderWerf

8/27/2007 9:13:00 PM

0

Roger Pack wrote:
> Question: anybody ever had the situation of a socket create or send that
> freezes all thread for multiples of 10s? (i.e. 10 or 20 or
> 30--exactly?) Odd, isn't it? Thanks! [note this is tcp sockets to IP
> addresses, not hostnames, so it is most likely not a DNS latency]
> -Roger

Does it help if you do

Socket.do_not_reverse_lookup = true

before you start using sockets?

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Roger Pack

8/28/2007 6:05:00 PM

0

I think that did it! Thank you!
Where is the documentation for this stuff???

I assume that it does a reverse lookup on every socket? If that's the
case I might <cough> put in a request to ruby to only do reverse DNS
when it is requested (lazily)...hmm...

Joel VanderWerf wrote:
> Roger Pack wrote:
>> Question: anybody ever had the situation of a socket create or send that
>> freezes all thread for multiples of 10s? (i.e. 10 or 20 or
>> 30--exactly?) Odd, isn't it? Thanks! [note this is tcp sockets to IP
>> addresses, not hostnames, so it is most likely not a DNS latency]
>> -Roger
>
> Does it help if you do
>
> Socket.do_not_reverse_lookup = true
>
> before you start using sockets?

--
Posted via http://www.ruby-....

Joel VanderWerf

8/28/2007 6:33:00 PM

0


Roger Pack wrote:
> I think that did it! Thank you!
> Where is the documentation for this stuff???

It is mentioned in the socket section in the Pickaxe (ed. 1 is on-line
somewhere, ed. 2 is worth buying). But if you don't know what you're
looking for that doesn't help...

It's just one of those gotchas that keeps coming up. A similar one is

Thread.abort_on_exception = true

(otherwise threads die silently on unhandled exceptions).

> I assume that it does a reverse lookup on every socket? If that's the
> case I might <cough> put in a request to ruby to only do reverse DNS
> when it is requested (lazily)...hmm...

IIRC, the reverse lookup only happens if you call something like
sock.addr or sock.peeraddr, and you've left Socket.do_not_reverse_lookup
= false.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

MenTaLguY

8/28/2007 7:25:00 PM

0

On Wed, 29 Aug 2007 03:33:04 +0900, Joel VanderWerf <vjoel@path.berkeley.edu> wrote:
> It's just one of those gotchas that keeps coming up. A similar one is
>
> Thread.abort_on_exception = true
>
> (otherwise threads die silently on unhandled exceptions).

You don't always want to do that, since you can recover the unhandled
exception that terminated a thread via Thread#join or Thread#value
and some libraries rely on this.

-mental



Roger Pack

8/28/2007 7:30:00 PM

0

> IIRC, the reverse lookup only happens if you call something like
> sock.addr or sock.peeraddr, and you've left Socket.do_not_reverse_lookup
> = false.

And of course I had been. Silly me. Thank you!
-Roger
--
Posted via http://www.ruby-....

Roger Pack

8/28/2007 7:40:00 PM

0

Mental Guy wrote:
> On Wed, 29 Aug 2007 03:33:04 +0900, Joel VanderWerf
>> It's just one of those gotchas that keeps coming up. A similar one is
>>
>> Thread.abort_on_exception = true
>>
>> (otherwise threads die silently on unhandled exceptions).
>
> You don't always want to do that, since you can recover the unhandled
> exception that terminated a thread via Thread#join or Thread#value
> and some libraries rely on this.

Interesting. I suppose I've never run into that. It helped me debug
things, mostly, and seemed useful, though I suppose handling exceptions
on join or checking value is another option.
Thanks.
-Roger

>
> -mental
--
Posted via http://www.ruby-....

Joel VanderWerf

8/28/2007 7:59:00 PM

0

MenTaLguY wrote:
> On Wed, 29 Aug 2007 03:33:04 +0900, Joel VanderWerf <vjoel@path.berkeley.edu> wrote:
>> It's just one of those gotchas that keeps coming up. A similar one is
>>
>> Thread.abort_on_exception = true
>>
>> (otherwise threads die silently on unhandled exceptions).
>
> You don't always want to do that, since you can recover the unhandled
> exception that terminated a thread via Thread#join or Thread#value
> and some libraries rely on this.

Good point. It's a global setting, so should be avoided. Better to set
this flag on threads individually using the instance method
#abort_on_exception and do so only in those cases where you don't use
join or value to propagate the exception to another thread. For example,
it would be a good idea to set this flag for a thread that is expected
to run indefinitely (no other thread is waiting for it to finish). Even
in that case, you might want to wrap the thread's code in a rescue
clause, if you just want to log the error and let other threads proceed.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407