Branch Coverage

blib/lib/PAGI/Server.pm
Criterion Covered Total %
branch 322 606 53.1


line true false branch
12 0 87 eval { do { require Future::XS; 1 } } ? :
15 0 87 if ($ENV{'PAGI_FUTURE_XS'}) { }
0 87 elsif ($FUTURE_XS_AVAILABLE) { }
16 0 0 if ($FUTURE_XS_AVAILABLE) { }
55 86 0 eval { do { require IO::Async::SSL; require IO::Socket::SSL; 1 } } ? :
67 86 0 eval { do { require PAGI::Server::Protocol::HTTP2; 'PAGI::Server::Protocol::HTTP2'->available } } ? :
2049 1 426 unless $self->{'app'} = delete $params->{'app'}
2062 56 370 if (my $ssl = $self->{'ssl'})
2063 2 54 if ($self->{'disable_tls'}) { }
2067 52 2 if (my $cert = $ssl->{'cert_file'})
2068 2 50 unless -e $cert
2069 0 50 unless -r $cert
2071 51 1 if (my $key = $ssl->{'key_file'})
2072 1 50 unless -e $key
2073 0 50 unless -r $key
2075 9 42 if (my $ca = $ssl->{'ca_file'})
2076 1 8 unless -e $ca
2077 0 8 unless -r $ca
2083 25 397 if ($listen) { }
20 377 elsif (defined $socket) { }
2085 2 23 if defined $host
2086 0 23 if defined $port
2087 0 23 if defined $socket
2088 0 23 if defined $socket_mode
2089 2 21 unless ref $listen eq "ARRAY" and @$listen
2094 0 29 unless ref $spec eq "HASH"
2095 10 19 if ($spec->{'socket'}) { }
2096 2 8 if $spec->{'host'}
2097 0 8 if $spec->{'port'}
2105 2 17 unless defined $spec->{'host'} and defined $spec->{'port'}
2117 2 18 if defined $host
2118 2 16 if defined $port
2140 52 358 if ($self->{'ssl'})
2142 52 0 if ($listener->{'type'} eq "tcp")
2150 31 379 exists $params->{'access_log'} ? :
2160 0 410 unless $valid_levels{$self->{'log_level'}}
2182 2 408 if (my $lt = $self->{'loop_type'})
2183 2 0 unless $lt =~ /\A[A-Za-z][A-Za-z0-9_]*(?:::[A-Za-z][A-Za-z0-9_]*)*\z/
2188 0 408 ($ENV{'PAGI_ENV'} // '') eq 'development' ? :
2214 88 320 if ($self->{'http2'})
2215 88 0 if ($HTTP2_AVAILABLE) { }
2227 80 8 unless ($self->{'ssl'})
2249 0 409 if (exists $params{'app'})
2252 0 409 if (exists $params{'host'})
2255 0 409 if (exists $params{'port'})
2258 0 409 if (exists $params{'socket'})
2261 0 409 if (exists $params{'socket_mode'})
2264 0 409 if (exists $params{'listen'})
2267 0 409 if (exists $params{'ssl'})
2270 0 409 if (exists $params{'extensions'})
2273 0 409 if (exists $params{'on_error'})
2276 0 409 if (exists $params{'access_log'})
2279 1 408 if (exists $params{'access_log_format'})
2285 0 409 if (exists $params{'quiet'})
2288 0 409 if (exists $params{'log_level'})
2292 0 0 unless $valid_levels{$level}
2296 0 409 if (exists $params{'timeout'})
2299 0 409 if (exists $params{'max_header_size'})
2302 0 409 if (exists $params{'max_header_count'})
2305 0 409 if (exists $params{'max_body_size'})
2308 0 409 if (exists $params{'workers'})
2311 0 409 if (exists $params{'max_requests'})
2314 0 409 if (exists $params{'listener_backlog'})
2317 0 409 if (exists $params{'shutdown_timeout'})
2320 0 409 if (exists $params{'max_receive_queue'})
2323 0 409 if (exists $params{'max_ws_frame_size'})
2326 0 409 if (exists $params{'max_connections'})
2329 0 409 if (exists $params{'request_timeout'})
2332 0 409 if (exists $params{'ws_idle_timeout'})
2335 0 409 if (exists $params{'sse_idle_timeout'})
2338 0 409 if (exists $params{'http2'})
2352 248 344 if $level_num < $self->{'_log_level_num'}
2353 339 5 if $self->{'quiet'} and $level ne "error"
2361 0 258 if ($self->{'disable_tls'})
2362 0 0 $TLS_AVAILABLE ? :
2364 39 219 if ($self->{'tls_enabled'})
2367 219 0 $TLS_AVAILABLE ? :
2374 4 254 if ($self->{'http2_enabled'})
2375 0 4 $self->{'h2c_enabled'} ? :
2377 254 0 $HTTP2_AVAILABLE ? :
2382 0 258 if $FUTURE_XS_ENABLED
2383 0 258 if $FUTURE_XS_AVAILABLE
2392 0 49 if ($self->{'disable_tls'})
2396 49 0 if $TLS_AVAILABLE
2417 209 43 unless my $ssl = $self->{'ssl'}
2419 0 43 unless $self->_check_tls_available
2423 43 0 if $ssl->{'cert_file'}
2424 43 0 if $ssl->{'key_file'}
2430 8 35 if ($ssl->{'verify_client'}) { }
2433 8 0 if $ssl->{'ca_file'}
2439 4 0 if ($self->{'http2'} and $HTTP2_AVAILABLE)
2452 43 0 unless exists $self->{'extensions'}{'tls'}
2504 0 0 if ($@)
2507 0 0 if ($error =~ /Address already in use/i) { }
0 0 elsif ($error =~ /Permission denied/i) { }
2524 0 1 if (my $loop_type = $self->{'loop_type'})
2525 0 0 unless $loop_type =~ /\A[A-Za-z][A-Za-z0-9_]*(?:::[A-Za-z][A-Za-z0-9_]*)*\z/
2529 0 0 unless eval { do { require $loop_file } }
2542 0 261 if $self->{'running'}
2545 15 246 if ($self->{'workers'} and $self->{'workers'} > 0)
2561 2 243 unless ($startup_result->{'success'})
2575 11 235 $spec->{'type'} eq 'unix' ? :
2579 3 243 if (my $inh = delete $inherited->{$match_key})
2584 2 1 unless ($handle)
2585 1 1 $inh->{'type'} eq 'unix' ? :
2587 1 1 if $inh->{'type'} eq "unix"
2588 0 2 unless $handle = $class->new_from_fd($inh->{'fd'}, "r")
2592 1 2 if ($inh->{'type'} eq "tcp" and $handle->can("sockport"))
2603 0 2 unless $weak_inner
2620 0 253 unless $weak_self
2632 10 233 if ($spec->{'type'} eq 'unix') { }
2634 1 9 if -e $spec->{'path'}
2642 0 10 if ($self->{'tls_enabled'})
2655 33 200 if (my $ssl_params = $self->_build_ssl_config)
2660 0 4 unless $weak_self
2669 10 233 if ($spec->{'type'} eq "unix")
2680 10 233 if defined $old_umask
2687 0 0 unless $weak_self
2692 243 0 if ($@)
2697 10 233 if ($spec->{'type'} eq 'unix') { }
2699 1 9 if (defined $spec->{'socket_mode'})
2705 233 0 if ($socket and $socket->can("sockport"))
2714 243 0 if ($rh)
2716 243 0 if (defined $fd)
2717 10 233 $spec->{'type'} eq 'unix' ? :
2721 3 240 length($ENV{'PAGI_REUSE'} // '') ? :
2735 0 0 if ($inh->{'handle'}) { }
2744 243 0 if @listen_entries
2752 0 0 if $shutdown_triggered
2772 0 0 if $weak_self and not $weak_self->{'quiet'}
2777 0 0 if $weak_self and not $weak_self->{'quiet'}
2789 0 243 if ($self->{'access_log'} and -t $self->{'access_log'})
2797 33 210 $self->{'tls_enabled'} ? :
2798 240 3 if (@listen_entries == 1) { }
2800 8 232 if ($spec->{'type'} eq 'unix') { }
2809 3 3 if ($s->{'type'} eq 'unix') { }
2819 0 243 if (($ENV{'PAGI_ENV'} // "") eq "production" and not $self->{'max_connections'})
2846 0 15 $spec->{'type'} eq 'unix' ? :
2850 0 15 if (my $inh = delete $inherited->{$match_key}) { }
0 15 elsif ($spec->{'type'} eq 'unix') { }
0 15 elsif ($reuseport) { }
2853 0 0 if ($inh->{'handle'}) { }
2856 0 0 $inh->{'type'} eq 'unix' ? :
2858 0 0 if $inh->{'type'} eq "unix"
2859 0 0 unless $socket = $class->new_from_fd($inh->{'fd'}, "r")
2863 0 0 if ($inh->{'type'} eq "tcp" and $socket->can("sockport"))
2873 0 0 if -e $spec->{'path'}
2885 0 0 unless $socket = "IO::Socket::UNIX"->new("Local", $spec->{'path'}, "Type", 1, "Listen", $self->{'listener_backlog'})
2890 0 0 if (defined $spec->{'socket_mode'})
2892 0 0 unless chmod $spec->{'socket_mode'}, $spec->{'path'}
2896 0 0 if ($socket and not $spec->{'_inherited'})
2900 0 0 length($ENV{'PAGI_REUSE'} // '') ? :
2913 0 0 unless my $probe_socket = "IO::Socket::INET"->new("LocalAddr", $spec->{'host'}, "LocalPort", $spec->{'port'}, "Proto", "tcp", "Listen", 1, "ReuseAddr", 1, "ReusePort", 1)
2930 0 15 unless $socket = "IO::Socket::INET"->new("LocalAddr", $spec->{'host'}, "LocalPort", $spec->{'port'}, "Proto", "tcp", "Listen", $self->{'listener_backlog'}, "ReuseAddr", 1, "Blocking", 0)
2938 15 0 if ($socket and not $spec->{'_inherited'})
2942 0 15 length($ENV{'PAGI_REUSE'} // '') ? :
2956 0 0 if ($inh->{'handle'}) { }
2965 15 0 if @listen_entries and $listen_entries[0]{'socket'}
2970 6 9 if ($self->{'ssl'})
2975 6 9 $self->{'ssl'} ? :
2978 0 15 $reuseport ? :
2985 0 15 if ($self->{'access_log'} and -t $self->{'access_log'})
2996 0 15 if ($s->{'type'} eq 'unix') { }
3007 0 15 if (($ENV{'PAGI_ENV'} // "") eq "production" and not $self->{'max_connections'})
3035 6 0 if ($self->{'heartbeat_timeout'} and $self->{'heartbeat_timeout'} > 0)
3043 0 0 unless $weak_self
3044 0 0 if $weak_self->{'shutting_down'}
3049 0 0 unless $info->{'heartbeat_rd'}
3057 0 0 if ($now - $info->{'last_heartbeat'} > $hb_timeout)
3073 0 6 if (my $old_master_pid = delete $ENV{'PAGI_MASTER_PID'})
3084 0 0 unless $weak_self_handoff
3087 0 0 if ($worker_count == 0)
3093 0 0 if (kill 0, $old_master_pid) { }
3119 7 259 if (my $reuse = $ENV{'PAGI_REUSE'})
3121 3 7 if ($entry =~ /^unix:(.+):(\d+)$/) { }
1 6 elsif ($entry =~ /^(\[.+?\]):(\d+):(\d+)$/) { }
4 2 elsif ($entry =~ /^(.+):(\d+):(\d+)$/) { }
3146 3 0 if (defined $listen_fds and $listen_fds =~ /^\d+$/ and $listen_fds > 0)
3147 1 2 if (defined $ENV{'LISTEN_PID'} and $ENV{'LISTEN_PID'} == $$)
3153 0 1 unless (open $fh, "+<&=", $fd)
3159 0 1 unless ($addr)
3166 0 1 if ($family == 1) { }
1 0 elsif ($family == 2) { }
3199 0 5 if $self->{'shutting_down'}
3204 5 0 if ($self->{'_heartbeat_check_timer'})
3212 5 0 unless ($self->{'_hot_restart_in_progress'})
3214 5 0 if ($entry->{'socket'})
3218 5 0 if ($self->{'listen_socket'})
3224 5 0 unless ($self->{'_hot_restart_in_progress'})
3227 5 0 if ($key and defined $ENV{'PAGI_REUSE'})
3229 5 0 if defined $ENV{'PAGI_REUSE'}
3235 5 0 unless ($self->{'_hot_restart_in_progress'})
3237 0 0 if ($entry->{'spec'}{'type'} eq "unix" and not $entry->{'spec'}{'_inherited'} and -e $entry->{'spec'}{'path'})
3251 0 5 unless (keys %{$$self{"worker_pids"};})
3262 0 0 unless $weak_self
3276 0 0 if $self->{'shutting_down'}
3291 0 0 unless $weak_self
3292 0 0 if (exists $weak_self->{'worker_pids'}{$pid})
3306 0 0 if ($self->{'_hot_restart_in_progress'})
3311 0 0 if ($self->{'shutting_down'})
3325 0 0 unless (defined $pid)
3332 0 0 if ($pid == 0)
3336 0 0 defined $ENV{'PAGI_ARGV'} ? :
3338 0 0 unless (exec $^X, $0, @args)
3352 0 0 if $self->{'shutting_down'}
3365 0 0 if $self->{'shutting_down'}
3368 0 0 unless @pids > 1
3388 24 0 if ($self->{'heartbeat_timeout'} and $self->{'heartbeat_timeout'} > 0)
3389 0 24 unless pipe $hb_rd, $hb_wr
3400 9 0 if $hb_rd
3409 0 15 unless defined $pid
3412 15 0 if ($hb_wr)
3428 0 7 unless $weak_self
3431 7 0 if (my $info = $weak_self->{'worker_pids'}{$exit_pid})
3432 7 0 if $info->{'heartbeat_rd'}
3439 0 7 if (my $timer_id = delete $weak_self->{'_restart_kill_timers'}{$exit_pid})
3445 0 7 if ($exit_code == 2) { }
0 14 elsif ($weak_self->{'running'} and not $weak_self->{'shutting_down'}) { }
3452 0 0 unless (delete $weak_self->{'_dont_respawn'}{$exit_pid})
3458 4 3 if ($weak_self->{'shutting_down'} and not keys %{$$weak_self{"worker_pids"};})
3460 4 0 if ($weak_self->{'_shutdown_kill_timer'})
3483 0 0 if (not $entry->{'socket'} and $reuseport and $spec->{'type'} eq "tcp")
3489 0 0 unless $entry->{'socket'} = "IO::Socket::INET"->new("LocalAddr", $spec->{'host'}, "LocalPort", $spec->{'bound_port'}, "Proto", "tcp", "Listen", $self->{'listener_backlog'}, "ReuseAddr", 1, "ReusePort", 1, "Blocking", 0)
3500 0 9 if ($s->{'type'} eq 'unix') { }
3501 0 0 defined $s->{'socket_mode'} ? :
3503 4 5 $s->{'ssl'} ? :
3540 9 0 if ($entry->{'spec'}{'type'} eq "tcp" and $entry->{'socket'} and $entry->{'socket'}->can("sockport"))
3559 0 9 if $shutdown_triggered
3580 0 9 unless ($startup_result->{'success'})
3584 0 9 if ($@)
3588 0 9 if $startup_error
3597 0 9 if ($startup_error)
3600 0 0 if $entry->{'socket'}
3609 0 9 unless $entry->{'socket'}
3619 0 5 unless $weak_server
3621 3 2 if ($use_ssl) { }
3627 3 0 if $weak_server
3630 0 0 if $weak_server
3646 0 0 unless $weak_server
3655 9 0 if ($heartbeat_wr)
3673 9 0 if $heartbeat_wr
3675 9 0 if $entry->{'socket'}
3687 2 258 if ($self->connection_count >= $max)
3695 2 42 if ($self->{'tls_enabled'} and $self->{'http2_enabled'})
3697 2 0 if ($handle and $handle->can("alpn_selected"))
3728 258 0 $listener_spec ? :
2 256 $self->{'http2_enabled'} ? :
3776 0 0 if ($error =~ /Too many open files|EMFILE|ENFILE/i) { }
3778 0 0 unless ($self->{'_accept_paused'})
3794 0 0 if $self->{'_accept_paused'}
3798 0 0 if ($self->{'_accept_pause_timer'})
3806 0 0 if ($listener and $listener->read_handle)
3811 0 0 if ($self->{'listener'} and not $self->{'_listen_entries'})
3812 0 0 if $self->{'listener'}->read_handle
3818 0 0 unless $weak_self and $weak_self->{'running'}
3825 0 0 if ($listener and $listener->read_handle)
3830 0 0 if ($weak_self->{'listener'} and not $weak_self->{'_listen_entries'})
3831 0 0 if $weak_self->{'listener'}->read_handle
3844 297 7 unless $self->{'is_worker'}
3845 5 2 unless $self->{'max_requests'} and $self->{'max_requests'} > 0
3849 0 2 if ($self->{'_request_count'} >= $self->{'max_requests'})
3850 0 0 if $self->{'_max_requests_shutdown_triggered'}
3891 175 172 if (@send_queue)
3903 172 171 if ($type eq 'lifespan.startup.complete') { }
2 169 elsif ($type eq 'lifespan.startup.failed') { }
167 2 elsif ($type eq 'lifespan.shutdown.complete') { }
0 2 elsif ($type eq 'lifespan.shutdown.failed') { }
3913 167 0 if ($self->{'shutdown_pending'})
3920 0 0 if ($self->{'shutdown_pending'})
3930 0 255 if ($receive_pending and not $receive_pending->is_ready)
3953 80 170 if (not $startup_complete->is_ready)
3977 80 168 unless $self->{'lifespan_supported'}
3978 0 168 unless $self->{'lifespan_send_queue'}
3989 168 0 if ($$receive_pending_ref and not $$receive_pending_ref->is_ready)
4002 0 168 if ($timeout_f->is_ready and not $self->{'shutdown_pending'}->is_ready)
4012 0 249 unless $self->{'running'}
4017 0 249 if ($self->{'_accept_pause_timer'})
4032 238 0 if ($key and not $self->{'_hot_restart_in_progress'} and defined $ENV{'PAGI_REUSE'})
4034 238 0 if defined $ENV{'PAGI_REUSE'}
4040 7 1 if ($entry->{'spec'}{'type'} eq "unix" and not $entry->{'spec'}{'_inherited'} and -e $entry->{'spec'}{'path'})
4054 0 248 unless ($shutdown_result->{'success'})
4079 10 0 unless $_->{'sse_mode'}
4085 248 1 if keys %{$$self{"connections"};} == 0
4097 1 0 if keys %{$$self{"connections"};} == 0
4100 0 0 if (keys %{$$self{"connections"};} > 0)
4105 0 0 if $conn and $conn->can("_close")
4126 411 34 if (exists $ACCESS_LOG_PRESETS{$format})
4138 2910 2473 if ($ch eq '%') { }
4140 0 2910 if $pos >= $len
4144 1 2909 if ($next eq '%') { }
13 2896 elsif ($next eq '{') { }
4152 0 13 if $end < 0
4157 0 13 if $pos >= $len or substr($format, $pos, 1) ne "i"
4165 9 18 if lc $h->[0] eq $lc_name
4182 411 2062 if ($next_pct < 0) { }
4196 1869 1582 if (ref $_) { }
4212 3 2 if defined $qs and length $qs
4219 15 246 defined $qs && length $qs ? :
4225 9 1 $size ? :
4233 2895 1 if (my $frag = $atoms{$atom})
4249 3 2 if $listener->{'type'} eq "unix"
4262 14 4 $self->{'running'} ? :
4278 10 512 $self->{'max_connections'} && $self->{'max_connections'} > 0 ? :