annotate worker_shutdown_timeout_h2.t @ 1961:fe6f22da53ec default tip

Tests: tests for usage of discarded body. The client_max_body_size limit should be ignored when the request body is already discarded. In HTTP/1.x, this is done by checking the r->discard_body flag when the body is being discarded, and because r->headers_in.content_length_n is 0 when it's already discarded. This, however, does not happen with HTTP/2 and HTTP/3, and therefore "error_page 413" does not work without relaxing the limit. Further, with proxy_pass, r->headers_in.content_length_n is used to determine length of the request body, and therefore is not correct if discarding of the request body isn't yet complete. While discarding the request body, r->headers_in.content_length_n contains the rest of the body to discard (or, in case of chunked request body, the rest of the current chunk to discard). Similarly, the $content_length variable uses r->headers_in.content_length if available, and also incorrect. The $content_length variable is used when proxying with fastcgi_pass, grpc_pass, and uwsgi_pass (scgi_pass uses the value calculated based on the actual request body buffers, and therefore works correctly).
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 27 Apr 2024 18:55:50 +0300
parents 236d038dc04a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1507
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for worker_shutdown_timeout and HTTP/2 with proxy.
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 use Test::Nginx::HTTP2;
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21 ###############################################################################
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDERR; $| = 1;
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24 select STDOUT; $| = 1;
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25
1513
02412b209838 Tests: testing worker_shutdown_timeout works with HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1512
diff changeset
26 my $t = Test::Nginx->new()->has(qw/http http_v2 proxy/)->plan(2);
1507
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 $t->write_file_expand('nginx.conf', <<'EOF');
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 %%TEST_GLOBALS%%
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32 daemon off;
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 worker_shutdown_timeout 10ms;
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 events {
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 }
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 http {
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 %%TEST_GLOBALS_HTTP%%
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 server {
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 listen 127.0.0.1:8080 http2;
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 server_name localhost;
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 location / {
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 proxy_pass http://127.0.0.1:8081;
1513
02412b209838 Tests: testing worker_shutdown_timeout works with HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1512
diff changeset
47 proxy_read_timeout 5s;
1507
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 }
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 }
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 }
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 EOF
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 $t->run_daemon(\&http_silent_daemon);
1900
236d038dc04a Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1693
diff changeset
54
236d038dc04a Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1693
diff changeset
55 # suppress deprecation warning
236d038dc04a Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1693
diff changeset
56
236d038dc04a Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1693
diff changeset
57 open OLDERR, ">&", \*STDERR; close STDERR;
236d038dc04a Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1693
diff changeset
58 $t->run();
236d038dc04a Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1693
diff changeset
59 open STDERR, ">&", \*OLDERR;
236d038dc04a Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1693
diff changeset
60
236d038dc04a Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1693
diff changeset
61 $t->waitforsocket('127.0.0.1:' . port(8081));
1507
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 ###############################################################################
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 my $s = Test::Nginx::HTTP2->new();
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 ok($s->new_stream(), 'new stream');
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67
1518
fca71a8ebf6d Tests: adjusted worker_shutdown_timeout_h2.t shutdown delay more.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1517
diff changeset
68 $s->h2_ping('SEE-THIS');
fca71a8ebf6d Tests: adjusted worker_shutdown_timeout_h2.t shutdown delay more.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1517
diff changeset
69 $s->read(all => [{ type => 'PING' }]);
fca71a8ebf6d Tests: adjusted worker_shutdown_timeout_h2.t shutdown delay more.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1517
diff changeset
70
1512
e84a3115bfe8 Tests: worker_shutdown_timeout_h2.t TODO adjusted.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1507
diff changeset
71 $t->stop();
e84a3115bfe8 Tests: worker_shutdown_timeout_h2.t TODO adjusted.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1507
diff changeset
72
1513
02412b209838 Tests: testing worker_shutdown_timeout works with HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1512
diff changeset
73 like($t->read_file('access.log'), qr/ (?!504)\d{3} /, 'shutdown timeout');
02412b209838 Tests: testing worker_shutdown_timeout works with HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1512
diff changeset
74
1507
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 ###############################################################################
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 sub http_silent_daemon {
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 my $server = IO::Socket::INET->new(
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 Proto => 'tcp',
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 LocalAddr => '127.0.0.1:' . port(8081),
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 Listen => 5,
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 Reuse => 1
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 )
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 or die "Can't create listening socket: $!\n";
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 while (my $client = $server->accept()) {
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 $client->autoflush(1);
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 while (<$client>) { }
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 }
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 }
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92
8958b5b53c25 Tests: HTTP/2 tests for alerts seen with worker_shutdown_timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93 ###############################################################################