Problem with local DRb on OS X

Rubyers & rubyees:

I’m getting delays making TCP connections to “localhost” on our OS X
box.

On Linux boxes (tried three of them, 1.6.7, 1.6.8, and 1.8 pre 2) I get
this:

[john@linux ~]$ irb
irb(main):002:0> require ‘socket’
=> true
irb(main):003:0> TCPSocket.open(“localhost”, 1234)

…and immediately…

Errno::ECONNREFUSED: Connection refused - “connect(2)”
from (irb):3:in `open’
from (irb):3
irb(main):004:0> exit

Which is exactly what I expect.

But on our Mac OS X box (running 1.8.0-preview 3):

[john@mac ~]$ irb
irb(main):002:0> require ‘socket’
=> true
irb(main):003:0> s = TCPSocket.open(“localhost”, 1234)

…at least 4 seconds delay here…

Errno::ECONNREFUSED: Connection refused - connect(2)
from (irb):3:in initialize' from (irb):3:in open’
from (irb):3
irb(main):004:0> exit

The same delay applies when connecting to a port that is running a
service, btw – the Linux box returns a TCPSocket right away and the
Mac succeeds after the delay.

I found this problem when running a DRuby example in Madeleine, so as
you might imagine, I’m rather eager to get this fixed so I can write
programs that operate without huge delays!

···


John Platte
Principal Consultant, NIKA Consulting
http://nikaconsulting.com/

Did you try using 127.0.0.1 instead of localhost? Maybe Roundevous (included
in OSX >= 10.1) tries to resolve localhost on the local network (using
multicast dns), instead of looking it up in the netinfo database…

greetings, Florian Pflug

···

On Tue, Jun 24, 2003 at 04:58:09AM +0900, John Platte wrote:

I’m getting delays making TCP connections to “localhost” on our OS X
box.

irb(main):003:0> TCPSocket.open(“localhost”, 1234)

Thanks for the suggestion. Yes, I did try 127.0.0.1, as well as the
network IP address of the computer (192.168…); they both worked, but
with about twice the delay.

I even recompiled Ruby 1.8.0 pre 3 after editing ext/socket/Makefile to
disable IPv6, but that didn’t change the delay at all.

I ran tcpflow to watch the loopback interface while I ran the DRb
transaction, and there was a bunch of binary stuff with NIS keywords
intermingled, and the ethernet interface was silent, so apparently the
lookup is going through NetInfo (and eventually succeeding). I’m not
sure what to poke at to learn more than this about where the delay is
occuring.

To compare with a simple C program doing the same thing on the same
computer, I just compiled & ran the code at
http://www.cs.wpi.edu/~cs3013/c03/week6-unixsock/week6-unixsock.html,
and it works great with no noticeable delay at all. The only thing I
had to tweak to compile it was taking the #ifndef unix…#else & the
#endif because apparently OS X doesn’t define “unix”. (I pasted the
diff for my changes to the server code below.)

Anyone have an idea how to fix Ruby, or do further troubleshooting?
This is a stock Mac box; it should just work, shouldn’t it?

Please help!

I’m getting delays making TCP connections to “localhost” on our OS X
box.

irb(main):003:0> TCPSocket.open(“localhost”, 1234)

Did you try using 127.0.0.1 instead of localhost? Maybe Roundevous
(included
in OSX >= 10.1) tries to resolve localhost on the local network (using
multicast dns), instead of looking it up in the netinfo database…

[john@mac ~/csock]$ diff -u sockserver-orig.c sockserver.c
— sockserver-orig.c Tue Jun 24 09:06:47 2003
+++ sockserver.c Thu Jan 1 03:28:43 1970
@@ -1,17 +1,11 @@
/* adapted from Sample 25_2 from "Computer Networks and Internets, 2nd
ed by Comer /
/
sockserver.c - code for example server program that uses TCP */

-#ifndef unix
-#define WIN32
-#include <windows.h>
-#include <winsock.h>
-#else
#define closesocket close
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
-#endif

#include <stdio.h>
#include <string.h>
[john@mac ~/csock]$

···

On Monday, Jun 23, 2003, at 19:24 America/Chicago, Florian G. Pflug wrote:

On Tue, Jun 24, 2003 at 04:58:09AM +0900, John Platte wrote:


John Platte
Principal Consultant, NIKA Consulting
http://nikaconsulting.com/