Skip Menu |

This queue is for tickets about the Net-NSCA-Client CPAN distribution.

Report information
The Basics
Id: 51061
Status: resolved
Priority: 0/
Queue: Net-NSCA-Client

People
Owner: Nobody in particular
Requestors: DOUGDUDE [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in:
  • 0.001
  • 0.002
  • 0.003
  • 0.004
  • 0.005
Fixed in: 0.006



Subject: Client randomly hangs up before server's message
The client will randomly hang up the connection before the server sends the initial packet and thus nothing is sent to the server by the client. When this happens, a message similar to this occurs: Attribute (unix_timestamp) does not pass the type constraint because: Validation failed for 'Int' failed with value undef at /usr/local/lib/perl5/site_perl/5.10.1/Net/NSCA/Client/Connection.pm line 154 Net::NSCA::Client::Connection::_build_initial_packet('Net::NSCA::Cli ent::Connection=HASH(0x288cd230)') called at accessor initial_packet defined at /usr/local/lib/perl5/site_perl/5.10.1/Net/NSCA/Client/Connection.pm line 39 Net::NSCA::Client::Connection::initial_packet('Net::NSCA::Client::Co nnection=HASH(0x288cd230)') called at /usr/local/lib/perl5/site_perl/5.10.1/Net/NSCA/Client/Connection.pm line 95 Net::NSCA::Client::Connection::send_data_packet('Net::NSCA::Client:: Connection=HASH(0x288cd230)', 'Net::NSCA::Client::DataPacket=HASH(0x285e4b7c)') called at /usr/local/lib/perl5/site_perl/5.10.1/Net/NSCA/Client.pm line 109 Net::NSCA::Client::send_report('Net::NSCA::Client=HASH(0x2833e618)', 'hostname', 'hostname', 'service', 'Ports', 'message', 'PORTS OK - 0 security problem(s), 3 Package(s) available for ...', 'status', 0) called at /usr/local/libexec/nagios/passive_ports line 73
This is likely due to the fact that the client will wait for the first burst of data to come in and use that instead of waiting until x number of bytes arrive.
The following patch should fix this: diff --git a/lib/Net/NSCA/Client/Connection.pm b/lib/Net/NSCA/Client/Connection.pm index dae14de..76b97e9 100644 --- a/lib/Net/NSCA/Client/Connection.pm +++ b/lib/Net/NSCA/Client/Connection.pm @@ -132,23 +132,10 @@ sub _build_initial_packet { # Create a scalar to store recieved bytes in my $received_bytes; - my $previously_read_bytes = 1; # Set to 1 to enter while loop - -# # Continue to read until server stops sending data -# while ($previously_read_bytes > 0) { -# # Read SOCKET_READ_SIZE bytes -# $previously_read_bytes = $self->socket->sysread( -# $received_bytes, -# $SOCKET_READ_SIZE -# ); -# -# if (!defined $previously_read_bytes) { -# # An error occurred during the read -# confess sprintf 'An error occurred while reading from the socket: %s', -# $ERRNO; -# } -# } - $received_bytes = join q{}, $self->socket->getlines; + + # Read the bytes + $self->socket->sysread($received_bytes, + Net::NSCA::Client::InitialPacket::_init_packet_struct()->sizeof('init_packet_struct')); # Create the initial packet object my $initial_packet = Net::NSCA::Client::InitialPacket->new($received_bytes); @@ -161,7 +148,7 @@ sub _build_socket { # Create the socket my $socket = IO::Socket::INET->new( - Blocking => 0, + Blocking => 1, PeerAddr => $self->remote_host, PeerPort => $self->remote_port, Proto => 'tcp',
Checked into release 0.006.