Branch Coverage

blib/lib/PAGI/Server.pm
Criterion Covered Total %
branch 356 638 55.8


line true false branch
12 0 107 eval { do { require Future::XS; 1 } } ? :
15 0 107 if ($ENV{'PAGI_FUTURE_XS'}) { }
0 107 elsif ($FUTURE_XS_AVAILABLE) { }
16 0 0 if ($FUTURE_XS_AVAILABLE) { }
55 107 0 eval { do { require IO::Async::SSL; require IO::Socket::SSL; 1 } } ? :
67 107 0 eval { do { require PAGI::Server::Protocol::HTTP2; 'PAGI::Server::Protocol::HTTP2'->available } } ? :
2183 1 381 unless $self->{'app'} = delete $params->{'app'}
2196 57 324 if (my $ssl = $self->{'ssl'})
2197 2 55 if ($self->{'disable_tls'}) { }
2201 53 2 if (my $cert = $ssl->{'cert_file'})
2202 1 52 unless -e $cert
2203 0 52 unless -r $cert
2205 53 1 if (my $key = $ssl->{'key_file'})
2206 1 52 unless -e $key
2207 0 52 unless -r $key
2209 9 44 if (my $ca = $ssl->{'ca_file'})
2210 1 8 unless -e $ca
2211 0 8 unless -r $ca
2217 26 352 if ($listen) { }
19 333 elsif (defined $socket) { }
2219 2 24 if defined $host
2220 0 24 if defined $port
2221 0 24 if defined $socket
2222 0 24 if defined $socket_mode
2223 2 22 unless ref $listen eq "ARRAY" and @$listen
2228 0 29 unless ref $spec eq "HASH"
2229 9 20 if ($spec->{'socket'}) { }
2230 2 7 if $spec->{'host'}
2231 0 7 if $spec->{'port'}
2239 2 18 unless defined $spec->{'host'} and defined $spec->{'port'}
2251 2 17 if defined $host
2252 2 15 if defined $port
2274 54 312 if ($self->{'ssl'})
2276 54 0 if ($listener->{'type'} eq "tcp")
2283 31 335 exists $params->{'access_log'} ? :
2293 0 366 unless $valid_levels{$self->{'log_level'}}
2315 1 365 unless $self->{'lifespan_mode'} =~ /\A(?:auto|on|off)\z/
2319 2 363 if (my $lt = $self->{'loop_type'})
2320 2 0 unless $lt =~ /\A[A-Za-z][A-Za-z0-9_]*(?:::[A-Za-z][A-Za-z0-9_]*)*\z/
2325 0 363 ($ENV{'PAGI_ENV'} // '') eq 'development' ? :
2352 90 273 if ($self->{'http2'})
2353 90 0 if ($HTTP2_AVAILABLE) { }
2366 83 7 unless ($self->{'ssl'})
2388 0 364 if (exists $params{'app'})
2391 0 364 if (exists $params{'host'})
2394 0 364 if (exists $params{'port'})
2397 0 364 if (exists $params{'socket'})
2400 0 364 if (exists $params{'socket_mode'})
2403 0 364 if (exists $params{'listen'})
2406 0 364 if (exists $params{'ssl'})
2409 0 364 if (exists $params{'extensions'})
2412 0 364 if (exists $params{'access_log'})
2415 1 363 if (exists $params{'access_log_format'})
2421 0 364 if (exists $params{'quiet'})
2424 0 364 if (exists $params{'log_level'})
2428 0 0 unless $valid_levels{$level}
2432 0 364 if (exists $params{'timeout'})
2435 0 364 if (exists $params{'max_header_size'})
2438 0 364 if (exists $params{'max_header_count'})
2441 0 364 if (exists $params{'max_body_size'})
2444 0 364 if (exists $params{'workers'})
2447 0 364 if (exists $params{'max_requests'})
2450 0 364 if (exists $params{'listener_backlog'})
2453 0 364 if (exists $params{'shutdown_timeout'})
2456 0 364 if (exists $params{'lifespan_startup_timeout'})
2459 0 364 if (exists $params{'lifespan_mode'})
2461 0 0 unless $mode =~ /\A(?:auto|on|off)\z/
2465 0 364 if (exists $params{'max_receive_queue'})
2468 0 364 if (exists $params{'max_ws_frame_size'})
2471 0 364 if (exists $params{'max_connections'})
2474 0 364 if (exists $params{'request_timeout'})
2477 0 364 if (exists $params{'ws_idle_timeout'})
2480 0 364 if (exists $params{'sse_idle_timeout'})
2483 0 364 if (exists $params{'http2'})
2497 197 278 if $level_num < $self->{'_log_level_num'}
2498 255 23 if $self->{'quiet'} and $level ne "error"
2506 0 210 if ($self->{'disable_tls'})
2507 0 0 $TLS_AVAILABLE ? :
2509 41 169 if ($self->{'tls_enabled'})
2512 169 0 $TLS_AVAILABLE ? :
2519 3 207 if ($self->{'http2_enabled'})
2520 0 3 $self->{'h2c_enabled'} ? :
2522 207 0 $HTTP2_AVAILABLE ? :
2527 0 210 if $FUTURE_XS_ENABLED
2528 0 210 if $FUTURE_XS_AVAILABLE
2537 0 51 if ($self->{'disable_tls'})
2541 51 0 if $TLS_AVAILABLE
2562 158 45 unless my $ssl = $self->{'ssl'}
2564 0 45 unless $self->_check_tls_available
2568 45 0 if $ssl->{'cert_file'}
2569 45 0 if $ssl->{'key_file'}
2578 45 0 if (grep {$_ eq $min_version;} @tls_order) { }
2581 45 181 if $v eq $min_version
2592 8 37 if ($ssl->{'verify_client'}) { }
2595 8 0 if $ssl->{'ca_file'}
2601 3 0 if ($self->{'http2'} and $HTTP2_AVAILABLE)
2614 45 0 unless exists $self->{'extensions'}{'tls'}
2666 0 2 if ($@)
2669 0 0 if ($error =~ /Address already in use/i) { }
0 0 elsif ($error =~ /Permission denied/i) { }
2684 1 1 if ($self->{'_workers_failed'})
2693 0 4 if (my $loop_type = $self->{'loop_type'})
2694 0 0 unless $loop_type =~ /\A[A-Za-z][A-Za-z0-9_]*(?:::[A-Za-z][A-Za-z0-9_]*)*\z/
2698 0 0 unless eval { do { require $loop_file } }
2711 0 214 if $self->{'running'}
2714 18 196 if ($self->{'workers'} and $self->{'workers'} > 0)
2730 4 192 unless ($startup_result->{'success'})
2744 11 184 $spec->{'type'} eq 'unix' ? :
2748 3 192 if (my $inh = delete $inherited->{$match_key})
2753 2 1 unless ($handle)
2754 1 1 $inh->{'type'} eq 'unix' ? :
2756 1 1 if $inh->{'type'} eq "unix"
2757 0 2 unless $handle = $class->new_from_fd($inh->{'fd'}, "r")
2761 1 2 if ($inh->{'type'} eq "tcp" and $handle->can("sockport"))
2772 0 2 unless $weak_inner
2789 0 198 unless $weak_self
2801 10 182 if ($spec->{'type'} eq 'unix') { }
2803 1 9 if -e $spec->{'path'}
2811 0 10 if ($self->{'tls_enabled'})
2824 35 147 if (my $ssl_params = $self->_build_ssl_config)
2829 0 4 unless $weak_self
2838 10 182 if ($spec->{'type'} eq "unix")
2849 10 182 if defined $old_umask
2856 0 0 unless $weak_self
2861 192 0 if ($@)
2866 10 182 if ($spec->{'type'} eq 'unix') { }
2868 1 9 if (defined $spec->{'socket_mode'})
2874 182 0 if ($socket and $socket->can("sockport"))
2883 192 0 if ($rh)
2885 192 0 if (defined $fd)
2886 10 182 $spec->{'type'} eq 'unix' ? :
2890 3 189 length($ENV{'PAGI_REUSE'} // '') ? :
2904 0 0 if ($inh->{'handle'}) { }
2913 192 0 if @listen_entries
2921 0 1 if $shutdown_triggered
2941 0 0 if $weak_self and not $weak_self->{'quiet'}
2946 0 0 if $weak_self and not $weak_self->{'quiet'}
2958 0 192 if ($self->{'access_log'} and -t $self->{'access_log'})
2966 35 157 $self->{'tls_enabled'} ? :
2967 189 3 if (@listen_entries == 1) { }
2969 8 181 if ($spec->{'type'} eq 'unix') { }
2978 3 3 if ($s->{'type'} eq 'unix') { }
2988 1 191 if (($ENV{'PAGI_ENV'} // "") eq "production" and not $self->{'max_connections'})
3015 0 18 $spec->{'type'} eq 'unix' ? :
3019 0 18 if (my $inh = delete $inherited->{$match_key}) { }
0 18 elsif ($spec->{'type'} eq 'unix') { }
0 18 elsif ($reuseport) { }
3022 0 0 if ($inh->{'handle'}) { }
3025 0 0 $inh->{'type'} eq 'unix' ? :
3027 0 0 if $inh->{'type'} eq "unix"
3028 0 0 unless $socket = $class->new_from_fd($inh->{'fd'}, "r")
3032 0 0 if ($inh->{'type'} eq "tcp" and $socket->can("sockport"))
3042 0 0 if -e $spec->{'path'}
3054 0 0 unless $socket = "IO::Socket::UNIX"->new("Local", $spec->{'path'}, "Type", 1, "Listen", $self->{'listener_backlog'})
3059 0 0 if (defined $spec->{'socket_mode'})
3061 0 0 unless chmod $spec->{'socket_mode'}, $spec->{'path'}
3065 0 0 if ($socket and not $spec->{'_inherited'})
3069 0 0 length($ENV{'PAGI_REUSE'} // '') ? :
3082 0 0 unless my $probe_socket = "IO::Socket::INET"->new("LocalAddr", $spec->{'host'}, "LocalPort", $spec->{'port'}, "Proto", "tcp", "Listen", 1, "ReuseAddr", 1, "ReusePort", 1)
3099 0 18 unless $socket = "IO::Socket::INET"->new("LocalAddr", $spec->{'host'}, "LocalPort", $spec->{'port'}, "Proto", "tcp", "Listen", $self->{'listener_backlog'}, "ReuseAddr", 1, "Blocking", 0)
3107 18 0 if ($socket and not $spec->{'_inherited'})
3111 0 18 length($ENV{'PAGI_REUSE'} // '') ? :
3125 0 0 if ($inh->{'handle'}) { }
3134 18 0 if @listen_entries and $listen_entries[0]{'socket'}
3139 6 12 if ($self->{'ssl'})
3144 6 12 $self->{'ssl'} ? :
3147 0 18 $reuseport ? :
3154 0 18 if ($self->{'access_log'} and -t $self->{'access_log'})
3165 0 18 if ($s->{'type'} eq 'unix') { }
3176 3 15 if (($ENV{'PAGI_ENV'} // "") eq "production" and not $self->{'max_connections'})
3204 7 0 if ($self->{'heartbeat_timeout'} and $self->{'heartbeat_timeout'} > 0)
3212 0 0 unless $weak_self
3213 0 0 if $weak_self->{'shutting_down'}
3218 0 0 unless $info->{'heartbeat_rd'}
3226 0 0 if ($now - $info->{'last_heartbeat'} > $hb_timeout)
3242 0 7 if (my $old_master_pid = delete $ENV{'PAGI_MASTER_PID'})
3253 0 0 unless $weak_self_handoff
3256 0 0 if ($worker_count == 0)
3262 0 0 if (kill 0, $old_master_pid) { }
3288 7 211 if (my $reuse = $ENV{'PAGI_REUSE'})
3290 3 7 if ($entry =~ /^unix:(.+):(\d+)$/) { }
1 6 elsif ($entry =~ /^(\[.+?\]):(\d+):(\d+)$/) { }
4 2 elsif ($entry =~ /^(.+):(\d+):(\d+)$/) { }
3315 3 0 if (defined $listen_fds and $listen_fds =~ /^\d+$/ and $listen_fds > 0)
3316 1 2 if (defined $ENV{'LISTEN_PID'} and $ENV{'LISTEN_PID'} == $$)
3322 0 1 unless (open $fh, "+<&=", $fd)
3328 0 1 unless ($addr)
3335 0 1 if ($family == 1) { }
1 0 elsif ($family == 2) { }
3368 0 5 if $self->{'shutting_down'}
3373 5 0 if ($self->{'_heartbeat_check_timer'})
3381 5 0 unless ($self->{'_hot_restart_in_progress'})
3383 5 0 if ($entry->{'socket'})
3387 5 0 if ($self->{'listen_socket'})
3393 5 0 unless ($self->{'_hot_restart_in_progress'})
3396 5 0 if ($key and defined $ENV{'PAGI_REUSE'})
3398 5 0 if defined $ENV{'PAGI_REUSE'}
3404 5 0 unless ($self->{'_hot_restart_in_progress'})
3406 0 0 if ($entry->{'spec'}{'type'} eq "unix" and not $entry->{'spec'}{'_inherited'} and -e $entry->{'spec'}{'path'})
3420 0 5 unless (keys %{$$self{"worker_pids"};})
3431 0 0 unless $weak_self
3445 0 0 if $self->{'shutting_down'}
3460 0 0 unless $weak_self
3461 0 0 if (exists $weak_self->{'worker_pids'}{$pid})
3475 0 0 if ($self->{'_hot_restart_in_progress'})
3480 0 0 if ($self->{'shutting_down'})
3494 0 0 unless (defined $pid)
3501 0 0 if ($pid == 0)
3505 0 0 defined $ENV{'PAGI_ARGV'} ? :
3507 0 0 unless (exec $^X, $0, @args)
3521 0 0 if $self->{'shutting_down'}
3534 0 0 if $self->{'shutting_down'}
3537 0 0 unless @pids > 1
3557 29 0 if ($self->{'heartbeat_timeout'} and $self->{'heartbeat_timeout'} > 0)
3558 0 29 unless pipe $hb_rd, $hb_wr
3569 11 0 if $hb_rd
3578 0 18 unless defined $pid
3581 18 0 if ($hb_wr)
3597 0 9 unless $weak_self
3600 9 0 if (my $info = $weak_self->{'worker_pids'}{$exit_pid})
3601 9 0 if $info->{'heartbeat_rd'}
3608 0 9 if (my $timer_id = delete $weak_self->{'_restart_kill_timers'}{$exit_pid})
3614 2 7 if ($exit_code == 2) { }
0 14 elsif ($weak_self->{'running'} and not $weak_self->{'shutting_down'}) { }
3621 0 0 unless (delete $weak_self->{'_dont_respawn'}{$exit_pid})
3627 5 4 if (not keys %{$$weak_self{"worker_pids"};})
3628 4 1 if ($weak_self->{'shutting_down'}) { }
3630 4 0 if ($weak_self->{'_shutdown_kill_timer'})
3666 0 0 if (not $entry->{'socket'} and $reuseport and $spec->{'type'} eq "tcp")
3672 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)
3683 0 11 if ($s->{'type'} eq 'unix') { }
3684 0 0 defined $s->{'socket_mode'} ? :
3686 4 7 $s->{'ssl'} ? :
3722 11 0 if ($entry->{'spec'}{'type'} eq "tcp" and $entry->{'socket'} and $entry->{'socket'}->can("sockport"))
3741 0 9 if $shutdown_triggered
3762 2 9 unless ($startup_result->{'success'})
3766 0 11 if ($@)
3770 2 9 if $startup_error
3779 2 9 if ($startup_error)
3782 2 0 if $entry->{'socket'}
3791 0 9 unless $entry->{'socket'}
3801 0 5 unless $weak_server
3803 3 2 if ($use_ssl) { }
3809 3 0 if $weak_server
3812 0 0 if $weak_server
3828 0 0 unless $weak_server
3837 9 0 if ($heartbeat_wr)
3855 9 0 if $heartbeat_wr
3857 9 0 if $entry->{'socket'}
3869 2 203 if ($self->connection_count >= $max)
3877 1 44 if ($self->{'tls_enabled'} and $self->{'http2_enabled'})
3879 1 0 if ($handle and $handle->can("alpn_selected"))
3910 203 0 $listener_spec ? :
1 202 $self->{'http2_enabled'} ? :
3958 0 0 if ($error =~ /Too many open files|EMFILE|ENFILE/i) { }
3960 0 0 unless ($self->{'_accept_paused'})
3976 0 0 if $self->{'_accept_paused'}
3980 0 0 if ($self->{'_accept_pause_timer'})
3988 0 0 if ($listener and $listener->read_handle)
3993 0 0 if ($self->{'listener'} and not $self->{'_listen_entries'})
3994 0 0 if $self->{'listener'}->read_handle
4000 0 0 unless $weak_self and $weak_self->{'running'}
4007 0 0 if ($listener and $listener->read_handle)
4012 0 0 if ($weak_self->{'listener'} and not $weak_self->{'_listen_entries'})
4013 0 0 if $weak_self->{'listener'}->read_handle
4026 230 7 unless $self->{'is_worker'}
4027 5 2 unless $self->{'max_requests'} and $self->{'max_requests'} > 0
4031 0 2 if ($self->{'_request_count'} >= $self->{'max_requests'})
4032 0 0 if $self->{'_max_requests_shutdown_triggered'}
4056 1 206 if ($self->{'lifespan_mode'} // "auto") eq "off"
4077 158 151 if (@send_queue)
4089 152 150 if ($type eq 'lifespan.startup.complete') { }
4 146 elsif ($type eq 'lifespan.startup.failed') { }
146 0 elsif ($type eq 'lifespan.shutdown.complete') { }
0 0 elsif ($type eq 'lifespan.shutdown.failed') { }
4099 146 0 if ($self->{'shutdown_pending'})
4106 0 0 if ($self->{'shutdown_pending'})
4116 0 206 if ($receive_pending and not $receive_pending->is_ready)
4135 151 50 $ok ? :
4137 49 152 if (not $startup_complete->is_ready) { }
2 150 elsif (defined $err) { }
4141 48 1 if (defined $err)
4143 1 48 if (($self->{'lifespan_mode'} // 'auto') eq 'on') { }
4147 1 0 defined $detail ? :
4159 47 1 if defined $detail
4185 206 0 if ($startup_timeout > 0) { }
4189 1 205 unless (defined $result)
4209 49 147 unless $self->{'lifespan_supported'}
4210 0 147 unless $self->{'lifespan_send_queue'}
4221 147 0 if ($$receive_pending_ref and not $$receive_pending_ref->is_ready)
4234 0 147 if ($timeout_f->is_ready and not $self->{'shutdown_pending'}->is_ready)
4244 0 197 unless $self->{'running'}
4249 0 197 if ($self->{'_accept_pause_timer'})
4264 186 0 if ($key and not $self->{'_hot_restart_in_progress'} and defined $ENV{'PAGI_REUSE'})
4266 186 0 if defined $ENV{'PAGI_REUSE'}
4272 7 1 if ($entry->{'spec'}{'type'} eq "unix" and not $entry->{'spec'}{'_inherited'} and -e $entry->{'spec'}{'path'})
4286 0 196 unless ($shutdown_result->{'success'})
4311 9 1 unless $_->{'sse_mode'}
4317 196 1 if keys %{$$self{"connections"};} == 0
4329 1 0 if keys %{$$self{"connections"};} == 0
4332 0 0 if (keys %{$$self{"connections"};} > 0)
4337 0 0 if $conn and $conn->can("_close")
4358 367 34 if (exists $ACCESS_LOG_PRESETS{$format})
4370 2602 2209 if ($ch eq '%') { }
4372 0 2602 if $pos >= $len
4376 1 2601 if ($next eq '%') { }
13 2588 elsif ($next eq '{') { }
4384 0 13 if $end < 0
4389 0 13 if $pos >= $len or substr($format, $pos, 1) ne "i"
4397 9 18 if lc $h->[0] eq $lc_name
4414 367 1842 if ($next_pct < 0) { }
4428 1421 1198 if (ref $_) { }
4444 3 2 if defined $qs and length $qs
4451 14 183 defined $qs && length $qs ? :
4457 9 1 $size ? :
4465 2587 1 if (my $frag = $atoms{$atom})
4481 2 2 if $listener->{'type'} eq "unix"
4494 17 4 $self->{'running'} ? :
4510 10 409 $self->{'max_connections'} && $self->{'max_connections'} > 0 ? :