Okay, very odd symptom. I'm writing a network server that forks off child processes and handles some data. After I'm done, I exit the child and close the socket handles.

This works great until the 64th iteration of the client. At the 65th attempt, the client fails to connect to the port of the server because the server has exited. This is without an error message of any kind, it just pops like a soap bubble.

This is on a win32 machine using Activestate. Also, it may be unrelated, but the number of handles that windoze sees goes up for each time the agent connects, but it never goes down, even with autoflush, handle closing, and child exiting. If I close the server, the handles go away, if the server crashes, they stay. Forever. What the?

I understand that fork/ithreads are beta, but what other choice do I have for parallel processing multiple connections? What's causing the crash?
Here's the server:

#!/Perl/bin/perl -w # Server Test use IO::Socket::INET; $SIG{INT} = 'IGNORE'; # Sub Defs sub control_socket { print "\nBinding Control Socket to Proto $proto Port $portnum for $lsn +ct listeners.\n"; $catcher=IO::Socket::INET->new( Proto=>$proto, LocalPort=>$portnum, Reuse=>1, Listen=>$lsnct, Timeout=>10) or die "This sucks, can't bind socket" ; $catcher->blocking(0); $catcher->autoflush(1); shutdown $catcher,1; } sub data_socket { $sys_id=$_[0] ; local $dataport=9000 + $sys_id ; local $childpid=$$; print "child:Using Dataport $dataport for system id $sys_id \n"; print "for childpid $childpid\n"; $input_port=IO::Socket::INET->new( Proto=>$proto, LocalPort=>$dataport, Reuse=>1, Listen=>10) #Timeout=>5) or die "child:This sucks, can't bind socket" ; $input_port->blocking(0); $input_port->autoflush(1); $data_port = $input_port->accept; sysread($data_port,$client_data,4096); print "child:Recieved client data of $client_data\n"; $datalength=length($client_data); print $data_port "$datalength\n"; print "child:Done with System $sys_id\n"; close $data_port; close $input_port; close $new_catcher; print "child: exit\n"; exit 0; } # Start Processing $proto="tcp"; $portnum=8888; $lsnct=10; $ct=0; print "Starting Test Server...\n"; control_socket; for ( ;; ) { #control_socket; $input_sysid=0; ++$ct; print "Waiting for new System Connection\n"; $new_catcher = $catcher->accept(); #sysread($new_catcher,$input_sysid,1024); #recv($new_catcher,$input_sysid,1024,0); if ($new_catcher) { $input_sysid = <$new_catcher>; close($new_catcher); } print "input system id is $input_sysid\n"; if ( ! $input_sysid ) {$input_sysid = 0; } print "Testing input for new connection\n"; if ( $input_sysid != 0 ) { print "Forking off new data session\n"; last unless (fork()); print "At Server Iteration $ct\n"; } } close $new_catcher; data_socket($input_sysid); # Server End
Here's the client, it runs every second counting connects:
#!/Perl/bin/Perl -w # W32 Agent use IO::Socket::INET; $ct=0; for ( ;; ) { $catapult=IO::Socket::INET->new( Proto=>"tcp", PeerAddr=>"localhost", PeerPort=>8888, #Timeout=>5 ) or die "Can't connect! DO SOMETHING!"; shutdown $catapult,0; $sys_id=1; $sysport=9000 + $sys_id; ++$ct; print $catapult "$sys_id\n"; print "Send sys id of $sys_id\n"; sleep 1; $data_port=IO::Socket::INET->new( Proto=>"tcp", PeerAddr=>"localhost", PeerPort=>$sysport, #Timeout=>5 ) or die "Can't connect data_port! DO SOMETHING!"; $msg="client1 data 12345\n"; $msglength=length($msg); #for ($i;$i <= 10;$i++){ print $data_port $msg; print "Sent data of length $msglength\n"; sysread($data_port,$servmsg,4096); print "Server said length was $servmsg\n"; if ($servmsg == $msglength){ print "We have a match!\n"; } else { print "************OUT OF SYNC*****************\n"; } #} print "Iteration number $ct\n"; close $data_port; close $catapult; if ( $ct == 50 ) { sleep 60;print "Sleeping\n"; } } # End Client
Many thanks if you can unravel this unruly conundrum!
M


In reply to 65 is the magic number! by Declarent

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.