OSX and Perlbal

Artur Bergman abergman at sixapart.com
Mon Sep 4 08:35:22 UTC 2006


Hi,

I just spent sometime making perlbal pass tests on OSX, attached are  
the patches for anyone to review ( I also committed them).


First of all, it makes proc work without BSD::Resource, it just skips  
out BSD::Resource specific things. This makes the test suite not just  
hang.

Second patch makes sure we only kill webservers if we are the main  
process, otherwise each child that fork && exited on accept killed  
off any other webservers it knew about, this was any launched before  
itself.

Third patch works around a bug in OSX where event_write gets fired on  
instead of event_err when a connect fails, this extra check makes  
sure there is no error on the socket. (Maybe it should be a darwin  
only check, it doesn't hurt linux but it is an extra syscall.

The only problem is this warning..

t/31-realworld...........ok 1/106Subroutine load redefined at /Users/ 
sky/Documents/Hack/perlbal/blib/lib/Perlbal/Plugin/Vhosts.pm line 20,  
<GEN5> line 1.
Subroutine unload redefined at /Users/sky/Documents/Hack/perlbal/blib/ 
lib/Perlbal/Plugin/Vhosts.pm line 48, <GEN5> line 1.
Subroutine register redefined at /Users/sky/Documents/Hack/perlbal/ 
blib/lib/Perlbal/Plugin/Vhosts.pm line 57, <GEN5> line 1.
Subroutine unregister redefined at /Users/sky/Documents/Hack/perlbal/ 
blib/lib/Perlbal/Plugin/Vhosts.pm line 71, <GEN5> line 1.
Subroutine vhost_selector redefined at /Users/sky/Documents/Hack/ 
perlbal/blib/lib/Perlbal/Plugin/Vhosts.pm line 79, <GEN5> line 1.

Which I am not sure if it is just warnings being on a bit too much  
(happens in selector too).


Cheers
Artur

==== Patch <osx_fixes> level 1
Source: e4de3bb6-b2f5-4e64-a777-46dac7559cef:/local:559
Target: 6caf28e9-730f-0410-b62b-a31386fe13fb:/trunk:554
         (http://code.sixapart.com/svn/perlbal)
Log:
r556 at hope:  sky | 2006-09-03 22:15:40 -0700
local branch
r557 at hope:  sky | 2006-09-03 22:39:06 -0700
If you don't have BSD::Resource, still return as mouch as possible so  
the test harness works
r558 at hope:  sky | 2006-09-03 23:17:23 -0700
make the webservers not kill off each other, otherwise later  
webservers got to kill off the older ones
r559 at hope:  sky | 2006-09-04 01:25:03 -0700
OSX thinks it is a good idea to return writeable when the connect  
fails, and then give you a EPIPE when you try writing, so explicitly  
check for errors, and if we get an EPIPE, treat it as as event_err

=== lib/Perlbal/Test/WebServer.pm
==================================================================
--- lib/Perlbal/Test/WebServer.pm       (revision 554)
+++ lib/Perlbal/Test/WebServer.pm       (patch osx_fixes level 1)
@@ -17,12 +17,13 @@
our @webserver_pids;
+my $testpid; # of the test suite's main program, the one running the  
HTTP client
+
END {
      # ensure we kill off the webserver
-    kill 9, @webserver_pids;
+    kill 9, @webserver_pids if $testpid == $$;
}
-my $testpid; # of the test suite's main program, the one running the  
HTTP client
sub start_webserver {
      my $port = new_port();
=== lib/Perlbal/BackendHTTP.pm
==================================================================
--- lib/Perlbal/BackendHTTP.pm  (revision 554)
+++ lib/Perlbal/BackendHTTP.pm  (patch osx_fixes level 1)
@@ -39,7 +39,7 @@
              'generation', # int; counts what generation we were  
spawned in
              'buffered_upload_mode', # bool; if on, we're doing a  
buffered upload transmit
              );
-use Socket qw(PF_INET IPPROTO_TCP SOCK_STREAM);
+use Socket qw(PF_INET IPPROTO_TCP SOCK_STREAM SOL_SOCKET SO_ERROR);
use Perlbal::ClientProxy;
@@ -120,6 +120,14 @@
sub close {
      my Perlbal::BackendHTTP $self = shift;
+    # OSX Gives EPIPE on bad connects, and doesn't fail the connect
+    # so lets treat EPIPE as a event_err so the logic there does
+    # the right thing
+    if ($_[0] eq 'EPIPE') {
+        $self->event_err;
+        return;
+    }
+
      # don't close twice
      return if $self->{closed};
@@ -258,6 +266,14 @@
          $NodeStats{$self->{ipport}}->{connects}++;
          $NodeStats{$self->{ipport}}->{lastconnect} = $now;
+        # OSX returns writeable even if the connect fails
+        # so explicitly check for the error
+        # TODO: make a smaller test case and show to the world
+        if (my $error = unpack('i', getsockopt($self->{sock},  
SOL_SOCKET, SO_ERROR))) {
+            $self->event_err;
+            return;
+        }
+
          if (defined $self->{service} && $self->{service}-> 
{verify_backend} &&
              !$self->{has_attention} && !defined $NoVerify{$self-> 
{ipport}}) {
=== lib/Perlbal.pm
==================================================================
--- lib/Perlbal.pm      (revision 554)
+++ lib/Perlbal.pm      (patch osx_fixes level 1)
@@ -456,18 +456,23 @@
sub MANAGE_proc {
      my $mc = shift->no_opts;
-    return $mc->err('This command is not available unless  
BSD::Resource is installed') unless $Perlbal::BSD_RESOURCE_AVAILABLE;
+    $mc->out('time: ' . time());
+    $mc->out('pid: ' . $$);
-    my $ru = BSD::Resource::getrusage();
-    my ($ut, $st) = ($ru->utime, $ru->stime);
-    my ($udelta, $sdelta) = ($ut - $lastutime, $st - $laststime);
+
+    if ($Perlbal::BSD_RESOURCE_AVAILABLE) {
+        my $ru = BSD::Resource::getrusage();
+        my ($ut, $st) = ($ru->utime, $ru->stime);
+        my ($udelta, $sdelta) = ($ut - $lastutime, $st - $laststime);
+        $mc->out("utime: $ut (+$udelta)");
+        $mc->out("stime: $st (+$sdelta)");
+        ($lastutime, $laststime, $lastreqs) = ($ut, $st, $reqs);
+    }
+
      my $rdelta = $reqs - $lastreqs;
-    $mc->out('time: ' . time());
-    $mc->out('pid: ' . $$);
-    $mc->out("utime: $ut (+$udelta)");
-    $mc->out("stime: $st (+$sdelta)");
      $mc->out("reqs: $reqs (+$rdelta)");
-    ($lastutime, $laststime, $lastreqs) = ($ut, $st, $reqs);
+    $lastreqs = $reqs;
+
      $mc->end;
}

==== BEGIN SVK PATCH BLOCK ====
Version: svk 1.07 (darwin)

eJyNVs1u20YQVq9C2wcoUGCbMLCESgn/ 
KdGI4CRW2yBBbNhOUqAolOVyKBGiSGV3accIA8Rtr70V
RY899NxDjz3k1CfppehTpLNLWpYTx6kggMvdmW9+dvjNfMEPNresajQyK8Myq/ 
1H98Jwl0o2u2a5
leFXEKey4IZXZXAImeFUWTE13CqnC8BTUZScqYWkfApSLVI2BzkaWQg3qOHGGuIUVqNGVBa5 
MIYa
fiI5gGFVwdag2nLUf2JYw0oAnmjYCYfDVKRFjuY9b4gCKG2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