| 1 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # HTTP connection to backend node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Copyright 2004, Danga Interactive, Inc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # Copyright 2005-2007, Six Apart, Ltd. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | package Perlbal::BackendHTTP; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 22 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 22 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 22 | ▶ | no warnings qw(deprecated); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 22 | ▶ | use base "Perlbal::Socket"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 22 | ▶ | use fields ('client', # Perlbal::ClientProxy connection, or undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 'service', # Perlbal::Service | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 'pool', # Perlbal::Pool; whatever pool we spawned from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 'ip', # IP scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 'port', # port scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 'ipport', # "$ip:$port" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 'reportto', # object; must implement reporter interface | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 'has_attention', # has been accepted by a webserver and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # we know for sure we're not just talking | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # to the TCP stack | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 'waiting_options', # if true, we're waiting for an OPTIONS * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # response to determine when we have attention | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 'disconnect_at', # time this connection will be disconnected, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # if it's kept-alive and backend told us. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # otherwise undef for unknown. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # The following only apply when the backend server sends | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # a content-length header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 'content_length', # length of document being transferred | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 'content_length_remain', # bytes remaining to be read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 'use_count', # number of requests this backend's been used for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 'generation', # int; counts what generation we were spawned in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 'buffered_upload_mode', # bool; if on, we're doing a buffered upload transmit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 'scratch' # for plugins | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 22 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 22 | ▶ | use Socket qw(PF_INET IPPROTO_TCP SOCK_STREAM SOL_SOCKET SO_ERROR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | AF_UNIX PF_UNSPEC | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 22 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 22 | ▶ | use IO::Handle; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 22 | ▶ | use Perlbal::ClientProxy; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # if this is made too big, (say, 128k), then perl does malloc instead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # of using its slab cache. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 22 | ▶ | use constant BACKEND_READ_SIZE => 61440; # 60k, to fit in a 64k slab | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # keys set here when an endpoint is found to not support persistent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # connections and/or the OPTIONS method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 22 | our %NoVerify; # { "ip:port" => next-verify-time } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 22 | our %NodeStats; # { "ip:port" => { ... } }; keep statistics about nodes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # constructor for a backend connection takes a service (pool) that it's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # for, and uses that service to get its backend IP/port, as well as the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # client that will be using this backend connection. final parameter is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # an options hashref that contains some options: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # reportto => object obeying reportto interface | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 25 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 25 | my Perlbal::BackendHTTP $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 25 | my ($svc, $ip, $port, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 25 | ▶ | $opts ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts ||= {}
MC/DC0%0/1
$opts ||= {}
$opts
Truth table50%1/2
A
A= $opts
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 25 | my $sock; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 25 | socket $sock, PF_INET, SOCK_STREAM, IPPROTO_TCP; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 25 | ▶ | unless ($sock && defined fileno($sock)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$sock and defined fileno $sock
MC/DC0%0/2
$sock and defined fileno $sock
$sock
defined fileno $sock
Truth table33%1/3
A and B
A= $sockB= defined fileno $sock
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | Perlbal::log('crit', "Error creating socket: $!"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 25 | my $inet_aton = Socket::inet_aton($ip); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 25 | ▶ | unless ($inet_aton) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | Perlbal::log('crit', "inet_aton failed creating socket for $ip"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 25 | IO::Handle::blocking($sock, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 25 | connect $sock, Socket::sockaddr_in($port, $inet_aton); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 25 | ▶ | $self = fields::new($self) unless ref $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 25 | $self->SUPER::new($sock); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 25 | Perlbal::objctor($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 25 | $self->{ip} = $ip; # backend IP | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 25 | $self->{port} = $port; # backend port | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 25 | $self->{ipport} = "$ip:$port"; # often used as key | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 25 | $self->{service} = $svc; # the service we're serving for | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 25 | $self->{pool} = $opts->{pool}; # what pool we came from. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 25 | ▶ | $self->{reportto} = $opts->{reportto} || $svc; # reportto if specified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$opts->{'reportto'} || $svc
MC/DC0%0/2
$opts->{'reportto'} || $svc
$opts->{'reportto'}
$svc
Truth table66%2/3
A || B
A= $opts->{'reportto'}B= $svc
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 25 | $self->state("connecting"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # mark another connection to this ip:port | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 25 | $NodeStats{$self->{ipport}}->{attempts}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 25 | $NodeStats{$self->{ipport}}->{lastattempt} = $self->{create_time}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # setup callback in case we get stuck in connecting land | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | ▶ | Perlbal::Socket::register_callback(15, sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | ▶ | if ($self->state eq 'connecting' || $self->state eq 'verifying_backend') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->state eq "connecting" or $self->state eq "verifying_backend"
MC/DC0%0/2
$self->state eq "connecting" or $self->state eq "verifying_backend"
$self->state eq "connecting"
$self->state eq "verifying_backend"
Truth table33%1/3
A or B
A= $self->state eq "connecting"B= $self->state eq "verifying_backend"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # shouldn't still be connecting/verifying ~15 seconds after create | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $self->close('callback_timeout'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 25 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # for header reading: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 25 | $self->init; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 25 | $self->watch_write(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 25 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 25 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 25 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 25 | $self->{req_headers} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 25 | $self->{res_headers} = undef; # defined w/ headers object once all headers in | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 25 | $self->{headers_string} = ""; # blank to start | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 25 | $self->{generation} = $self->{service}->{generation}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 25 | $self->{read_size} = 0; # total bytes read from client | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 25 | $self->{client} = undef; # Perlbal::ClientProxy object, initially empty | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # until we ask our service for one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 25 | $self->{has_attention} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 25 | $self->{use_count} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 25 | $self->{buffered_upload_mode} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | sub new_process { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_process: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my ($class, $svc, $prog) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | my ($psock, $csock); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | socketpair($csock, $psock, AF_UNIX, SOCK_STREAM, PF_UNSPEC) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | or die "socketpair: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $csock->autoflush(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $psock->autoflush(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my $pid = fork; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | unless (defined $pid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | warn "fork failed: $!\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # child process | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | unless ($pid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | close(STDIN); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | close(STDOUT); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | #close(STDERR); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | open(STDIN, '<&', $psock); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | open(STDOUT, '>&', $psock); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | #open(STDERR, ">/dev/null"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | exec $prog; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | close($psock); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my $sock = $csock; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my $self = fields::new($class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $self->SUPER::new($sock); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | Perlbal::objctor($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | $self->{ipport} = $prog; # often used as key | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $self->{service} = $svc; # the service we're serving for | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | $self->{reportto} = $svc; # reportto interface (same as service) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | $self->state("connecting"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | $self->init; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $self->watch_write(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 18 | ▶ | sub close { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
close: called CC=6 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 18 | my Perlbal::BackendHTTP $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # OSX Gives EPIPE on bad connects, and doesn't fail the connect | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # so lets treat EPIPE as a event_err so the logic there does | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # the right thing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 18 | ▶ | if (defined $_[0] && $_[0] eq 'EPIPE') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $_[0] and $_[0] eq "EPIPE"
MC/DC0%0/2
defined $_[0] and $_[0] eq "EPIPE"
defined $_[0]
$_[0] eq "EPIPE"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "EPIPE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | $self->event_err; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # don't close twice | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 18 | ▶ | return if $self->{closed}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # this closes the socket and sets our closed flag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 18 | $self->SUPER::close(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # tell our client that we're gone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 18 | ▶ | if (my $client = $self->{client}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 16 | $client->backend(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 16 | $self->{client} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # tell our owner that we're gone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 18 | ▶ | if (my $reportto = $self->{reportto}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 18 | $reportto->note_backend_close($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 18 | $self->{reportto} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # return our defined generation counter with no parameter, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # or set our generation if given a parameter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 272 | ▶ | sub generation { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generation: called CC=2 SCAR=8.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 272 | my Perlbal::BackendHTTP $self = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 272 | ▶ | return $self->{generation} unless $_[1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | return $self->{generation} = $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # return what ip and port combination we're using | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | sub ipport { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ipport: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | my Perlbal::BackendHTTP $self = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | return $self->{ipport}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # called to tell backend that the client has gone on to do something else now. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | sub forget_client { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
forget_client: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my Perlbal::BackendHTTP $self = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $self->{client} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # called by service when it's got a client for us, or by ourselves | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | # when we asked for a client. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # returns true if client assignment was accepted. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 144 | ▶ | sub assign_client { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
assign_client: called CC=10 SCAR=24.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 144 | my Perlbal::BackendHTTP $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 144 | my Perlbal::ClientProxy $client = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 144 | ▶ | return 0 if $self->{client}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 144 | my $svc = $self->{service}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # set our client, and the client's backend to us | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 144 | $svc->mark_node_used($self->{ipport}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 144 | $self->{client} = $client; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 144 | $self->state("sending_req"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 144 | $self->{client}->backend($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 144 | my Perlbal::HTTPHeaders $hds = $client->{req_headers}->clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 144 | $self->{req_headers} = $hds; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 144 | my $client_ip = $client->peer_ip_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | # I think I've seen this be undef in practice. Double-check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 144 | ▶ | unless ($client_ip) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | warn "Undef client_ip ($client) in assign_client. Closing."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | $client->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | # Use HTTP/1.0 to backend (FIXME: use 1.1 and support chunking) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 144 | $hds->set_version("1.0"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 144 | my $persist = $svc->{persist_backend}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 144 | ▶ | $hds->header("Connection", $persist ? "keep-alive" : "close"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 144 | ▶ | if ($svc->{enable_reproxy}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 33 | $hds->header("X-Proxy-Capabilities", "reproxy-file"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # decide whether we trust the upstream or not, to give us useful | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # forwarding info headers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 144 | ▶ | if ($svc->trusted_ip($client_ip)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | # yes, we trust our upstream, so just append our client's IP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | # to the existing list of forwarded IPs, if we're a blind proxy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | # then don't append our IP to the end of the list. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | unless ($svc->{blind_proxy}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | my @ips = split /,\s*/, ($hds->header("X-Forwarded-For") || ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$hds->header('X-Forwarded-For') || ''
MC/DC0%0/1
$hds->header('X-Forwarded-For') || ''
$hds->header('X-Forwarded-For')
Truth table0%0/2
A
A= $hds->header('X-Forwarded-For')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $hds->header("X-Forwarded-For", join ", ", @ips, $client_ip); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # no, don't trust upstream (untrusted client), so remove all their | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # forwarding headers and tag their IP as the x-forwarded-for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 144 | $hds->header("X-Forwarded-For", $client_ip); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 144 | $hds->header("X-Host", undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 144 | $hds->header("X-Forwarded-Host", undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 144 | $self->tcp_cork(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 144 | $client->state('backend_req_sent'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 144 | $self->{content_length} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 144 | $self->{content_length_remain} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | # run hooks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 144 | ▶ | return 1 if $svc->run_hook('backend_client_assigned', $self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # now cleanup the headers before we send to the backend | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 144 | ▶ | $svc->munge_headers($hds) if $svc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 144 | $self->write($hds->to_string_ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 144 | ▶ | $self->write(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 144 | $self->tcp_cork(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 144 | ▶ | if (my $client = $self->{client}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | # start waiting on a reply | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 144 | $self->watch_read(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 144 | $self->state("wait_res"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 144 | $client->state('wait_res'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 144 | $client->backend_ready($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 144 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 144 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | # called by ClientProxy after we tell it our backend is ready and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # it has an upload ready on disk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 29 | ▶ | sub invoke_buffered_upload_mode { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
invoke_buffered_upload_mode: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 29 | my Perlbal::BackendHTTP $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | # so, we're receiving a buffered upload, we need to go ahead and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # start the buffered upload retransmission to backend process. we | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # have to turn watching for writes on, since that's what is doing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | # the triggering, NOT the normal client proxy watch for read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 29 | $self->{buffered_upload_mode} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 29 | $self->watch_write(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | # Backend | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 103 | ▶ | sub event_write { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
event_write: called CC=14 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 103 | my Perlbal::BackendHTTP $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 103 | print "Backend $self is writeable!\n" if Perlbal::DEBUG >= 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 103 | my $now = time(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | delete $NoVerify{$self->{ipport}} if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | defined $NoVerify{$self->{ipport}} && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 103 | ▶ | $NoVerify{$self->{ipport}} < $now; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $Perlbal::BackendHTTP::NoVerify{$self->{"ipport"}} and $Perlbal::BackendHTTP::NoVerify{$self->{"ipport"}} < $now
MC/DC0%0/2
defined $Perlbal::BackendHTTP::NoVerify{$self->{"ipport"}} and $Perlbal::BackendHTTP::NoVerify{$self->{"ipport"}} < $now
defined $Perlbal::BackendHTTP::NoVerify{$self->{"ipport"}}
$Perlbal::BackendHTTP::NoVerify{$self->{"ipport"}} < $now
Truth table33%1/3
A and B
A= defined $Perlbal::BackendHTTP::NoVerify{$self->{"ipport"}}B= $Perlbal::BackendHTTP::NoVerify{$self->{"ipport"}} < $now
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 103 | ▶ | if (! $self->{client} && $self->{state} eq "connecting") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $self->{"client"} and $self->{"state"} eq "connecting"
MC/DC50%1/2
not $self->{"client"} and $self->{"state"} eq "connecting"
not $self->{"client"}
$self->{"state"} eq "connecting"
Truth table66%2/3
not(A) and B
A= not $self->{"client"}B= $self->{"state"} eq "connecting"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | # not interested in writes again until something else is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 25 | $self->watch_write(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 25 | $NodeStats{$self->{ipport}}->{connects}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 25 | $NodeStats{$self->{ipport}}->{lastconnect} = $now; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | # OSX returns writeable even if the connect fails | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | # so explicitly check for the error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | # TODO: make a smaller test case and show to the world | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 25 | ▶ | if (my $error = unpack('i', getsockopt($self->{sock}, SOL_SOCKET, SO_ERROR))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 1 | $self->event_err; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 24 | ▶ | if (defined $self->{service} && $self->{service}->{verify_backend} && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
defined $self->{"service"} and $self->{"service"}{"verify_backend"} and not $self->{"has_attention"} and not defined $Perlbal::BackendHTTP::NoVerify{$self->{"ipport"}}
defined $self->{"service"} and $self->{"service"}{"verify_backend"} and not $self->{"has_attention"}
defined $self->{"service"} and $self->{"service"}{"verify_backend"}
MC/DC25%1/4
defined $self->{"service"} and $self->{"service"}{"verify_backend"} and not $self->{"has_attention"} and not defined $Perlbal::BackendHTTP::NoVerify{$self->{"ipport"}}
defined $self->{"service"}
$self->{"service"}{"verify_backend"}
not $self->{"has_attention"}
not defined $Perlbal::BackendHTTP::NoVerify{$self->{"ipport"}}
Truth table40%2/5
A and B and not(C) and not(D)
A= defined $self->{"service"}B= $self->{"service"}{"verify_backend"}C= not $self->{"has_attention"}D= not defined $Perlbal::BackendHTTP::NoVerify{$self->{"ipport"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | !$self->{has_attention} && !defined $NoVerify{$self->{ipport}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 1 | ▶ | return if $self->{service}->run_hook('backend_write_verify', $self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | # the backend should be able to answer this incredibly quickly. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 1 | $self->write("OPTIONS " . $self->{service}->{verify_backend_path} . " HTTP/1.0\r\nConnection: keep-alive\r\n\r\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 1 | $self->watch_read(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 1 | $self->{waiting_options} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 1 | $self->{content_length_remain} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 1 | $self->state("verifying_backend"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | # register our boredom (readiness for a client/request) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 23 | $self->state("bored"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 23 | $self->{reportto}->register_boredom($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 24 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | # if we have a client, and we're currently doing a buffered upload | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | # sendfile, then tell the client to continue sending us data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 78 | ▶ | if ($self->{client} && $self->{buffered_upload_mode}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"client"} and $self->{"buffered_upload_mode"}
MC/DC50%1/2
$self->{"client"} and $self->{"buffered_upload_mode"}
$self->{"client"}
$self->{"buffered_upload_mode"}
Truth table66%2/3
A and B
A= $self->{"client"}B= $self->{"buffered_upload_mode"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 29 | $self->{client}->continue_buffered_upload($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 29 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 49 | my $done = $self->write(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 49 | ▶ | $self->watch_write(0) if $done; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 1 | ▶ | sub verify_success { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verify_success: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 1 | my Perlbal::BackendHTTP $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 1 | $self->{waiting_options} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 1 | $self->{has_attention} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 1 | $NodeStats{$self->{ipport}}->{verifies}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 1 | $self->next_request(1); # initial | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | sub verify_failure { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verify_failure: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | my Perlbal::BackendHTTP $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | $NoVerify{$self->{ipport}} = time() + 60; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | $self->{reportto}->note_bad_backend_connect($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | $self->close('no_keep_alive'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 1 | ▶ | sub event_read_waiting_options { # : void | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
event_read_waiting_options: called CC=9 SCAR=27.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 1 | my Perlbal::BackendHTTP $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 1 | ▶ | if (defined $self->{service}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 1 | ▶ | return if $self->{service}->run_hook('backend_readable_verify', $self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 1 | ▶ | if ($self->{content_length_remain}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | # the HTTP/1.1 spec says OPTIONS responses can have content-lengths, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | # but the meaning of the response is reserved for a future spec. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | # this just gobbles it up for. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | my $bref = $self->read(BACKEND_READ_SIZE); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ▶ | return $self->verify_failure unless defined $bref; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | $self->{content_length_remain} -= length($$bref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } elsif (my $hd = $self->read_response_headers) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | # see if we have keep alive support | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 1 | ▶ | return $self->verify_failure unless $hd->res_keep_alive_options; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 1 | $self->{content_length_remain} = $hd->header("Content-Length"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | # if we've got the option response and read any response data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | # if present: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 1 | ▶ | if ($self->{res_headers} && ! $self->{content_length_remain}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"res_headers"} and not $self->{"content_length_remain"}
MC/DC0%0/2
$self->{"res_headers"} and not $self->{"content_length_remain"}
$self->{"res_headers"}
not $self->{"content_length_remain"}
Truth table33%1/3
A and not(B)
A= $self->{"res_headers"}B= not $self->{"content_length_remain"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 1 | $self->verify_success; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 163 | ▶ | sub handle_response { # : void | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_response: called CC=29 SCAR=35.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 163 | my Perlbal::BackendHTTP $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 163 | my Perlbal::HTTPHeaders $hd = $self->{res_headers}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 163 | my Perlbal::ClientProxy $client = $self->{client}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 163 | print "BackendHTTP: handle_response\n" if Perlbal::DEBUG >= 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 163 | my $res_code = $hd->response_code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | # keep a rolling window of the last 500 response codes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 163 | ▶ | my $ref = ($NodeStats{$self->{ipport}}->{responsecodes} ||= []); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$Perlbal::BackendHTTP::NodeStats{$self->{"ipport"}}{"responsecodes"} ||= []
MC/DC100%1/1
$Perlbal::BackendHTTP::NodeStats{$self->{"ipport"}}{"responsecodes"} ||= []
$Perlbal::BackendHTTP::NodeStats{$self->{"ipport"}}{"responsecodes"}
Truth table100%2/2
A
A= $Perlbal::BackendHTTP::NodeStats{$self->{"ipport"}}{"responsecodes"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 163 | push @$ref, $res_code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 163 | ▶ | if (scalar(@$ref) > 500) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | shift @$ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | # call service response received function | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 163 | ▶ | return if $self->{reportto}->backend_response_received($self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | # standard handling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 162 | $self->state("xfer_res"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 162 | $client->state("xfer_res"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 162 | $self->{has_attention} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | # RFC 2616, Sec 4.4: Messages MUST NOT include both a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | # Content-Length header field and a non-identity | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | # transfer-coding. If the message does include a non- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | # identity transfer-coding, the Content-Length MUST be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | # ignored. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 162 | my $te = $hd->header("Transfer-Encoding"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 162 | ▶ | if ($te && $te !~ /\bidentity\b/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$te and not $te =~ /\bidentity\b/i
MC/DC0%0/2
$te and not $te =~ /\bidentity\b/i
$te
not $te =~ /\bidentity\b/i
Truth table33%1/3
A and not(B)
A= $teB= not $te =~ /\bidentity\b/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | $hd->header("Content-Length", undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 162 | my Perlbal::HTTPHeaders $rqhd = $self->{req_headers}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | # setup our content length so we know how much data to expect, in general | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | # we want the content-length from the response, but if this was a head request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | # we know it's a 0 length message the client wants | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 162 | ▶ | if ($rqhd->request_method eq 'HEAD') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 2 | $self->{content_length} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 160 | $self->{content_length} = $hd->content_length; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 162 | ▶ | $self->{content_length_remain} = $self->{content_length} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'content_length'} || 0
MC/DC100%1/1
$self->{'content_length'} || 0
$self->{'content_length'}
Truth table100%2/2
A
A= $self->{'content_length'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 162 | ▶ | my $reproxy_cache_for = $hd->header('X-REPROXY-CACHE-FOR') || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$hd->header('X-REPROXY-CACHE-FOR') || 0
MC/DC100%1/1
$hd->header('X-REPROXY-CACHE-FOR') || 0
$hd->header('X-REPROXY-CACHE-FOR')
Truth table100%2/2
A
A= $hd->header('X-REPROXY-CACHE-FOR')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | # special cases: reproxying and retrying after server errors: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 162 | ▶ | if ((my $rep = $hd->header('X-REPROXY-FILE')) && $self->may_reproxy) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition66%2/3
my $rep = $hd->header("X-REPROXY-FILE") and $self->may_reproxy
MC/DC50%1/2
my $rep = $hd->header("X-REPROXY-FILE") and $self->may_reproxy
my $rep = $hd->header("X-REPROXY-FILE")
$self->may_reproxy
Truth table66%2/3
A and B
A= my $rep = $hd->header("X-REPROXY-FILE")B= $self->may_reproxy
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | # make the client begin the async IO while we move on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 10 | $self->next_request; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 10 | $client->start_reproxy_file($rep, $hd); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 10 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | ▶ | } elsif ((my $urls = $hd->header('X-REPROXY-URL')) && $self->may_reproxy) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
my $urls = $hd->header("X-REPROXY-URL") and $self->may_reproxy
MC/DC50%1/2
my $urls = $hd->header("X-REPROXY-URL") and $self->may_reproxy
my $urls = $hd->header("X-REPROXY-URL")
$self->may_reproxy
Truth table66%2/3
A and B
A= my $urls = $hd->header("X-REPROXY-URL")B= $self->may_reproxy
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 17 | $self->next_request; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 17 | ▶ | $self->{service}->add_to_reproxy_url_cache($rqhd, $hd) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | if $reproxy_cache_for; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 17 | $client->start_reproxy_uri($hd, $urls); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 17 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | ▶ | } elsif ((my $svcname = $hd->header('X-REPROXY-SERVICE')) && $self->may_reproxy) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
my $svcname = $hd->header("X-REPROXY-SERVICE") and $self->may_reproxy
MC/DC0%0/2
my $svcname = $hd->header("X-REPROXY-SERVICE") and $self->may_reproxy
my $svcname = $hd->header("X-REPROXY-SERVICE")
$self->may_reproxy
Truth table33%1/3
A and B
A= my $svcname = $hd->header("X-REPROXY-SERVICE")B= $self->may_reproxy
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | $self->next_request; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | $self->{client} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | $client->start_reproxy_service($hd, $svcname); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | ▶ | } elsif ($res_code == 500 && | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
$res_code == 500 and $rqhd->request_method =~ /^GET|HEAD$/ and $client->should_retry_after_500($self)
$res_code == 500 and $rqhd->request_method =~ /^GET|HEAD$/
MC/DC0%0/3
$res_code == 500 and $rqhd->request_method =~ /^GET|HEAD$/ and $client->should_retry_after_500($self)
$res_code == 500
$rqhd->request_method =~ /^GET|HEAD$/
$client->should_retry_after_500($self)
Truth table50%2/4
A and B and C
A= $res_code == 500B= $rqhd->request_method =~ /^GET|HEAD$/C= $client->should_retry_after_500($self)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | $rqhd->request_method =~ /^GET|HEAD$/ && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | $client->should_retry_after_500($self)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | # eh, 500 errors are rare. just close and don't spend effort reading | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | # rest of body's error message to no client. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | $self->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | # and tell the client to try again with a new backend | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | $client->retry_after_500($self->{service}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | # regular path: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 135 | ▶ | my $res_source = $client->{primary_res_hdrs} || $hd; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$client->{'primary_res_hdrs'} || $hd
MC/DC0%0/2
$client->{'primary_res_hdrs'} || $hd
$client->{'primary_res_hdrs'}
$hd
Truth table66%2/3
A || B
A= $client->{'primary_res_hdrs'}B= $hd
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 135 | my $thd = $client->{res_headers} = $res_source->clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | # if we had an alternate primary response header, make sure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | # we send the real content-length (from the reproxied URL) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | # and not the one the first server gave us | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 135 | ▶ | if ($client->{primary_res_hdrs}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 19 | $thd->header('Content-Length', $hd->header('Content-Length')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 19 | $thd->header('X-REPROXY-FILE', undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 19 | $thd->header('X-REPROXY-URL', undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 19 | $thd->header('X-REPROXY-EXPECTED-SIZE', undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 19 | $thd->header('X-REPROXY-CACHE-FOR', undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | # also update the response code, in case of 206 partial content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 19 | my $rescode = $hd->response_code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 19 | ▶ | if ($rescode == 206 || $rescode == 416) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$rescode == 206 or $rescode == 416
MC/DC100%2/2
$rescode == 206 or $rescode == 416
$rescode == 206
$rescode == 416
Truth table100%3/3
A or B
A= $rescode == 206B= $rescode == 416
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 4 | $thd->code($rescode); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 4 | ▶ | $thd->header('Accept-Ranges', $hd->header('Accept-Ranges')) if $hd->header('Accept-Ranges'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 4 | ▶ | $thd->header('Content-Range', $hd->header('Content-Range')) if $hd->header('Content-Range'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 19 | ▶ | $thd->code(200) if $thd->response_code == 204; # upgrade HTTP No Content (204) to 200 OK. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | # setup_keepalive will set Connection: and Keep-Alive: headers for us | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | # as well as setup our HTTP version appropriately | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 135 | $client->setup_keepalive($thd); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 135 | ▶ | my $svc = ref $self->{service} eq 'Perlbal::Service' ? $self->{service} : $client->{service}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 135 | $svc->run_hook('modify_response_headers', $self, $client); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 135 | print " writing response headers to client\n" if Perlbal::DEBUG >= 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 135 | $client->write($thd->to_string_ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | print(" content_length=", (defined $self->{content_length} ? $self->{content_length} : "(undef)"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 135 | " remain=", (defined $self->{content_length_remain} ? $self->{content_length_remain} : "(undef)"), "\n") | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | if Perlbal::DEBUG >= 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 135 | $svc->run_hook('prepend_body', $self, $client); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 135 | ▶ | if (defined $self->{content_length} && ! $self->{content_length_remain}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"content_length"} and not $self->{"content_length_remain"}
MC/DC50%1/2
defined $self->{"content_length"} and not $self->{"content_length_remain"}
defined $self->{"content_length"}
not $self->{"content_length_remain"}
Truth table66%2/3
A and not(B)
A= defined $self->{"content_length"}B= not $self->{"content_length_remain"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 4 | print " done. detaching.\n" if Perlbal::DEBUG >= 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | # order important: next_request detaches us from client, so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | # $client->close can't kill us | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 4 | $self->next_request; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 4 | ▶ | $client->write(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 4 | $client->backend_finished; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 4 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 27 | ▶ | sub may_reproxy { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
may_reproxy: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 27 | my Perlbal::BackendHTTP $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 27 | my Perlbal::Service $svc = $self->{service}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 27 | ▶ | return 0 unless $svc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 27 | return $svc->{enable_reproxy}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | # Backend | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 295 | ▶ | sub event_read { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
event_read: called CC=9 SCAR=25.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 295 | my Perlbal::BackendHTTP $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 295 | print "Backend $self is readable!\n" if Perlbal::DEBUG >= 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 295 | ▶ | return $self->event_read_waiting_options if $self->{waiting_options}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 294 | my Perlbal::ClientProxy $client = $self->{client}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | # with persistent connections, sometimes we have a backend and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | # no client, and backend becomes readable, either to signal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | # to use the end of the stream, or because a bad request error, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | # which I can't totally understand. in any case, we have | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | # no client so all we can do is close this backend. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 294 | ▶ | return $self->close('read_with_no_client') unless $client; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 294 | ▶ | unless ($self->{res_headers}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 163 | ▶ | return unless $self->read_response_headers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 163 | return $self->handle_response; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | # if our client's behind more than the max limit, stop buffering | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 131 | ▶ | if ($client->too_far_behind_backend) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | $self->watch_read(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | $client->{backend_stalled} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 131 | my $bref = $self->read(BACKEND_READ_SIZE); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 131 | ▶ | if (defined $bref) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 131 | $client->write($bref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | # HTTP/1.0 keep-alive support to backend. we just count bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | # until we hit the end, then we know we can send another | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | # request on this connection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 131 | ▶ | if ($self->{content_length}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 131 | $self->{content_length_remain} -= length($$bref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 131 | ▶ | if (! $self->{content_length_remain}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | # order important: next_request detaches us from client, so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | # $client->close can't kill us | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 131 | $self->next_request; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 131 | ▶ | $client->write(sub { $client->backend_finished; }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 131 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | # backend closed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | print "Backend $self is done; closing...\n" if Perlbal::DEBUG >= 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | $client->backend(undef); # disconnect ourselves from it | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | $self->{client} = undef; # .. and it from us | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | $self->close('backend_disconnect'); # close ourselves | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | ▶ | $client->write(sub { $client->backend_finished; }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | # if $initial is on, then don't increment use count | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 163 | ▶ | sub next_request { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next_request: called CC=12 SCAR=25.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 163 | my Perlbal::BackendHTTP $self = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 163 | my $initial = $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | # don't allow this if we're closed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 163 | ▶ | return if $self->{closed}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | # set alive_time so reproxy can intelligently reuse this backend | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 163 | my $now = time(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 163 | $self->{alive_time} = $now; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 163 | ▶ | $NodeStats{$self->{ipport}}->{requests}++ unless $initial; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 163 | $NodeStats{$self->{ipport}}->{lastresponse} = $now; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 163 | my $hd = $self->{res_headers}; # response headers | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | # verify that we have keep-alive support. by passing $initial to res_keep_alive, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | # we signal that req_headers may be undef (if we just did an options request) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | return $self->close('next_request_no_persist') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 163 | ▶ | unless $hd->res_keep_alive($self->{req_headers}, $initial); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | # and now see if we should closed based on the pool we're from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | return $self->close('pool_requested_closure') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 148 | ▶ | if $self->{pool} && ! $self->{pool}->backend_should_live($self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"pool"} and not $self->{"pool"}->backend_should_live($self)
MC/DC0%0/2
$self->{"pool"} and not $self->{"pool"}->backend_should_live($self)
$self->{"pool"}
not $self->{"pool"}->backend_should_live($self)
Truth table66%2/3
A and not(B)
A= $self->{"pool"}B= not $self->{"pool"}->backend_should_live($self)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | # we've been used | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 148 | ▶ | $self->{use_count}++ unless $initial; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | # service specific | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 148 | ▶ | if (my Perlbal::Service $svc = $self->{service}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | # keep track of how many times we've been used, and don't | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | # keep using this connection more times than the service | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | # is configured for. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 148 | ▶ | if ($svc->{max_backend_uses} && ($self->{use_count} > $svc->{max_backend_uses})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$svc->{"max_backend_uses"} and $self->{"use_count"} > $svc->{"max_backend_uses"}
MC/DC0%0/2
$svc->{"max_backend_uses"} and $self->{"use_count"} > $svc->{"max_backend_uses"}
$svc->{"max_backend_uses"}
$self->{"use_count"} > $svc->{"max_backend_uses"}
Truth table33%1/3
A and B
A= $svc->{"max_backend_uses"}B= $self->{"use_count"} > $svc->{"max_backend_uses"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 0 | return $self->close('exceeded_max_uses'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | # if backend told us, keep track of when the backend | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | # says it's going to boot us, so we don't use it within | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | # a few seconds of that time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 148 | ▶ | if (($hd->header("Keep-Alive") || '') =~ /\btimeout=(\d+)/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$hd->header('Keep-Alive') || ''
MC/DC100%1/1
$hd->header('Keep-Alive') || ''
$hd->header('Keep-Alive')
Truth table100%2/2
A
A= $hd->header('Keep-Alive')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 19 | $self->{disconnect_at} = $now + $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 129 | $self->{disconnect_at} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 148 | $self->{client} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 148 | $self->state("bored"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 148 | $self->watch_write(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 148 | $self->{req_headers} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 148 | $self->{res_headers} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 148 | $self->{headers_string} = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 148 | $self->{req_headers} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 148 | $self->{read_size} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 148 | $self->{content_length_remain} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 148 | $self->{content_length} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 148 | $self->{buffered_upload_mode} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 148 | $self->{reportto}->register_boredom($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 148 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | # Backend: bad connection to backend | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 1 | ▶ | sub event_err { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
event_err: called CC=4 SCAR=16.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 1 | my Perlbal::BackendHTTP $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | # FIXME: we get this after backend is done reading and we disconnect, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | # hence the misc checks below for $self->{client}. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 1 | print "BACKEND event_err\n" if | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | Perlbal::DEBUG >= 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 1 | ▶ | if ($self->{client}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | # request already sent to backend, then an error occurred. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | # we don't want to duplicate POST requests, so for now | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | # just fail | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | # TODO: if just a GET request, retry? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | $self->{client}->close('backend_error'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | $self->close('error'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 1 | ▶ | if ($self->{state} eq "connecting" || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"state"} eq "connecting" or $self->{"state"} eq "verifying_backend"
MC/DC0%0/2
$self->{"state"} eq "connecting" or $self->{"state"} eq "verifying_backend"
$self->{"state"} eq "connecting"
$self->{"state"} eq "verifying_backend"
Truth table33%1/3
A or B
A= $self->{"state"} eq "connecting"B= $self->{"state"} eq "verifying_backend"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | $self->{state} eq "verifying_backend") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | # then tell the service manager that this connection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | # failed, so it can spawn a new one and note the dead host | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 1 | $self->{reportto}->note_bad_backend_connect($self, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | # close ourselves first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 1 | $self->close("error"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | # Backend | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | ▶ | sub event_hup { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
event_hup: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | my Perlbal::BackendHTTP $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | print "HANGUP for $self\n" if Perlbal::DEBUG; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | $self->close("after_hup"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | ▶ | sub as_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 0 | my Perlbal::BackendHTTP $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | my $ret = $self->SUPER::as_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | ▶ | my $name = $self->{sock} ? getsockname($self->{sock}) : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | ▶ | my $lport = $name ? (Socket::sockaddr_in($name))[0] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 0 | ▶ | $ret .= ": localport=$lport" if $lport; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | ▶ | if (my Perlbal::ClientProxy $cp = $self->{client}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 0 | $ret .= "; client=$cp->{fd}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | $ret .= "; uses=$self->{use_count}; $self->{state}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 0 | ▶ | if (defined $self->{service} && $self->{service}->{verify_backend}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"service"} and $self->{"service"}{"verify_backend"}
MC/DC0%0/2
defined $self->{"service"} and $self->{"service"}{"verify_backend"}
defined $self->{"service"}
$self->{"service"}{"verify_backend"}
Truth table0%0/3
A and B
A= defined $self->{"service"}B= $self->{"service"}{"verify_backend"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 0 | $ret .= "; has_attention="; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 0 | ▶ | $ret .= $self->{has_attention} ? 'yes' : 'no'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | ▶ | sub die_gracefully { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
die_gracefully: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | # see if we need to die | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 0 | my Perlbal::BackendHTTP $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 0 | ▶ | $self->close('graceful_death') if $self->state eq 'bored'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | Perlbal::objdtor($_[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 0 | $_[0]->SUPER::DESTROY; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 22 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | # Local Variables: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | # mode: perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | # c-basic-indent: 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | # indent-tabs-mode: nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | # End: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||