You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Stefan Eissing <st...@eissing.org> on 2022/01/25 12:11:58 UTC

mpm event assertion failures

Also, while running the http2 test suite, I get repeated assert failures in event.c:1230

if (rv != APR_SUCCESS && !APR_STATUS_IS_EEXIST(rv)) {
->  AP_DEBUG_ASSERT(0);
    TO_QUEUE_REMOVE(cs->sc->wc_q, cs);
    apr_thread_mutex_unlock(timeout_mutex);
    ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, APLOGNO(03465)
                 "process_socket: apr_pollset_add failure for "
                 "write completion");
    close_connection(cs);
    signal_threads(ST_GRACEFUL);
}

Seems something is fishy with the recent changes.

Kind regards,
Stefan

Re: mpm event assertion failures

Posted by Yann Ylavic <yl...@gmail.com>.
Stefan,

On Tue, Jan 25, 2022 at 1:12 PM Stefan Eissing <st...@eissing.org> wrote:
>
> Also, while running the http2 test suite, I get repeated assert failures in event.c:1230
>
> if (rv != APR_SUCCESS && !APR_STATUS_IS_EEXIST(rv)) {
> ->  AP_DEBUG_ASSERT(0);
>     TO_QUEUE_REMOVE(cs->sc->wc_q, cs);
>     apr_thread_mutex_unlock(timeout_mutex);
>     ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, APLOGNO(03465)
>                  "process_socket: apr_pollset_add failure for "
>                  "write completion");
>     close_connection(cs);
>     signal_threads(ST_GRACEFUL);
> }

This EBADF(?) in mpm_event seems to imply an APR_POLL_FILE type, which
possibly comes from the mplx's pipes?
They should not end up in the MPM pollset AIUI but I'm wondering if it
could be a synchronization / corruption issue.
The mplx pollset is not created with APR_POLLSET_THREADSAFE, can the
calls to apr_pollset_add/remove/poll() be concurrent there?


Cheers;
Yann.

Re: mpm event assertion failures

Posted by Graham Leggett <mi...@sharp.fm>.
On 09 Feb 2022, at 15:08, Ruediger Pluem <rp...@apache.org> wrote:

> Probably you get hit by this?
> 
> https://github.com/apache/httpd/blob/46a9db4c6f9fadca4e362872021fa62a37908ece/server/mpm/event/event.c#L2096-L2101
> 
> If a client sends a request on a keepalive connection it should be prepared that the connection gets closed without a reply and it
> should retry if the request is idempotent. This is how I read RFC7230 6.3.1:
> 
> https://datatracker.ietf.org/doc/html/rfc7230#section-6.3.1

This seems to be it - ab was trying to test whether the current request was keepalive, which it could never be given the request had been closed before read. The fix is to keep track of whether this connection has ever been kept alive, and check that instead.

Fixed in r1897912.

Regards,
Graham
—


Re: mpm event assertion failures

Posted by Stefan Eissing <st...@eissing.org>.

> Am 09.02.2022 um 22:49 schrieb Graham Leggett <mi...@sharp.fm>:
> 
> On 09 Feb 2022, at 17:43, Yann Ylavic <yl...@gmail.com> wrote:
> 
>> So ab is (appropriately?) reporting errors for kept-alive connections
>> that had to be shutdown earlier than KeepAliveTimeout, although I
>> suspect that it would report the same after the KeepAliveTimeout.
> 
> ab has a code path that checks for this case and ignores the closed connection, but the test for this was based on whether the current connection had keepalive headers - which it could never be, because, the connection closed before the headers arrived. I added a check as to whether the connection had been kept alive in the past, and now the errors are all gone.
> 
> Switching from MacOS to Rawhide (on a very low powered server that is designed to save electricity), httpd with your PR ticks along nicely at 10 000 concurrent requests. Will try some more testing on a Linux VM on my Macbook Pro, it should be quicker.

Nice!

> 
> [minfrin@kingdom httpd-trunk]$ /tmp/httpd-trunk/bin/ab -R 10 -n 4096000 -c 10000 https://localhost/index.html
> This is ApacheBench, Version 2.3 <$Revision: 1897912 $>
> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://web.archive.org/web/20000304112933/http://www.zeustech.net/
> Licensed to The Apache Software Foundation, http://www.apache.org/
> 
> Benchmarking localhost (be patient)
> ^C
> 
> Server Software:        Apache/2.5.1-dev
> Server Hostname:        localhost
> Server Port:            443
> SSL/TLS Protocol:       TLSv1.2,ECDHE-RSA-AES256-GCM-SHA384,2048,256
> Server Temp Key:        X25519 253 bits
> TLS Server Name:        localhost
> 
> Document Path:          /index.html
> Document Length:        191 bytes
> 
> Concurrency Level:      10000
> Concurrency achieved:   10000
> Rampup delay:           10 [ms]
> Time taken for tests:   391.854 seconds
> Complete requests:      136274
> Failed requests:        0
> Total transferred:      58427992 bytes
> HTML transferred:       26074174 bytes
> Requests per second:    347.77 [#/sec] (mean)
> Time per request:       28754.873 [ms] (mean)
> Time per request:       2.875 [ms] (mean, across all concurrent requests)
> Transfer rate:          145.61 [Kbytes/sec] received
> 
> Connection Times (ms)
>               min  mean[+/-sd] median   max
> Connect:       16 15427 5534.2  16315   33304
> Processing:     5 8640 2503.2   9722   11456
> Waiting:        1 4313 1306.0   4890    6407
> Total:         21 24067 7782.9  26160   41561
> 
> Percentage of the requests served within a certain time (ms)
>   50%  26160
>   66%  26394
>   75%  26633
>   80%  31010
>   90%  31586
>   95%  31837
>   98%  32071
>   99%  32326
>  100%  41561 (longest request)
> 
> Regards,
> Graham
> —
> 


Re: mpm event assertion failures

Posted by Graham Leggett <mi...@sharp.fm>.
On 09 Feb 2022, at 17:43, Yann Ylavic <yl...@gmail.com> wrote:

> So ab is (appropriately?) reporting errors for kept-alive connections
> that had to be shutdown earlier than KeepAliveTimeout, although I
> suspect that it would report the same after the KeepAliveTimeout.

ab has a code path that checks for this case and ignores the closed connection, but the test for this was based on whether the current connection had keepalive headers - which it could never be, because, the connection closed before the headers arrived. I added a check as to whether the connection had been kept alive in the past, and now the errors are all gone.

Switching from MacOS to Rawhide (on a very low powered server that is designed to save electricity), httpd with your PR ticks along nicely at 10 000 concurrent requests. Will try some more testing on a Linux VM on my Macbook Pro, it should be quicker.

[minfrin@kingdom httpd-trunk]$ /tmp/httpd-trunk/bin/ab -R 10 -n 4096000 -c 10000 https://localhost/index.html
This is ApacheBench, Version 2.3 <$Revision: 1897912 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://web.archive.org/web/20000304112933/http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
^C

Server Software:        Apache/2.5.1-dev
Server Hostname:        localhost
Server Port:            443
SSL/TLS Protocol:       TLSv1.2,ECDHE-RSA-AES256-GCM-SHA384,2048,256
Server Temp Key:        X25519 253 bits
TLS Server Name:        localhost

Document Path:          /index.html
Document Length:        191 bytes

Concurrency Level:      10000
Concurrency achieved:   10000
Rampup delay:           10 [ms]
Time taken for tests:   391.854 seconds
Complete requests:      136274
Failed requests:        0
Total transferred:      58427992 bytes
HTML transferred:       26074174 bytes
Requests per second:    347.77 [#/sec] (mean)
Time per request:       28754.873 [ms] (mean)
Time per request:       2.875 [ms] (mean, across all concurrent requests)
Transfer rate:          145.61 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       16 15427 5534.2  16315   33304
Processing:     5 8640 2503.2   9722   11456
Waiting:        1 4313 1306.0   4890    6407
Total:         21 24067 7782.9  26160   41561

Percentage of the requests served within a certain time (ms)
  50%  26160
  66%  26394
  75%  26633
  80%  31010
  90%  31586
  95%  31837
  98%  32071
  99%  32326
 100%  41561 (longest request)

Regards,
Graham
—


Re: mpm event assertion failures

Posted by Yann Ylavic <yl...@gmail.com>.
On Wed, Feb 9, 2022 at 4:43 PM Yann Ylavic <yl...@gmail.com> wrote:
>
> With PR #294 this specific case shouldn't happen anymore (thanks to
> https://github.com/apache/httpd/pull/294/commits/7089813e13bba0f25bd34df4c643cf5878e6e043).

That link broke with my rebases..
It's currently https://github.com/apache/httpd/pull/294/commits/b009a66cb2d86a58182a5703bbaa1847e785f2b0,
but in case it breaks again later that's "mpm_event: Pending queue for
when active connections have no worker available" in the PR #294
series.

Re: mpm event assertion failures

Posted by Yann Ylavic <yl...@gmail.com>.
On Wed, Feb 9, 2022 at 2:09 PM Ruediger Pluem <rp...@apache.org> wrote:
>
> On 2/9/22 1:25 PM, Graham Leggett wrote:
> > On 08 Feb 2022, at 19:01, Yann Ylavic <ylavic.dev@gmail.com <ma...@gmail.com>> wrote:
> >
> >>> The most concurrent requests I can get out of MacOS appears to be roughly 2000 concurrent requests before “connection reset by
> >>> peer” kills the test.
> >>>
> >>> One small detail I have uncovered is that a small percentage of requests fail, caused by httpd gracefully shutting the
> >>> connection down before returning a response. Stopping ab in a debugger confirms that openssl returns SSL_ERROR_ZERO_RETURN on
> >>> read, which is what openssl does when the other side gracefully triggers close notify.
> >>>
> >>> Is this something anyone has seen before while I go digging?
> >>
> >> I tried with ab too and indeed there was some (dead-)locking issue at
> >> some point, could you please retry with the latest pushes I just made
> >> to the PR?
> >
> > I tried with the latest patch, then I tried with no patch (vanilla trunk) and got the same results.
> >
> > Working backwards looking for graceful attempts to shut down the SSL connection, I found this:
> >
> > ::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [info] [pid 8747] mod_ssl.c(681): [client ::1:56237] AH01964: Connection to child
> > 29 established (server localhost:443)
> > ::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] ssl_engine_kernel.c(2402): [client ::1:56237] AH02043: SSL
> > virtual host for servername localhost found
> > ::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] ssl_engine_kernel.c(2262): [client ::1:56237] AH02041: Protocol:
> > TLSv1.2, Cipher: ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)
> > ::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] ssl_engine_kernel.c(415): [client ::1:56237] AH02034: Initial
> > (No.1) HTTPS request received for child 29 (server localhost:443)
> > ::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] mod_authz_core.c(843): [client ::1:56237] AH01628: authorization
> > result: granted (no directives)
> > ::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] ssl_engine_kernel.c(415): [client ::1:56237] AH02034: Subsequent
> > (No.2) HTTPS request received for child 27 (server localhost:443)
> > ::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] mod_authz_core.c(843): [client ::1:56237] AH01628: authorization
> > result: granted (no directives)
> > ::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] ssl_engine_kernel.c(415): [client ::1:56237] AH02034: Subsequent
> > (No.3) HTTPS request received for child 37 (server localhost:443)
> > ::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] mod_authz_core.c(843): [client ::1:56237] AH01628: authorization
> > result: granted (no directives)
> > ::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] ssl_engine_io.c(1184): [client ::1:56237] AH02001: Connection
> > closed to child 29 with standard shutdown (server localhost:443)
> >
> > It seems reasonably normal, except what looks like is happening is when "Connection closed to child 29 with standard shutdown” is
> > run, this seems to happen before a response is sent to the client.
> >
> > ab then goes “that’s weird, I was trying to read a response, but got a connection closed instead”, and marks that request as failed.
> >
> > This is limited to keepalive requests, and happens after a number of keepalive requests have been correctly handled.
>
> Probably you get hit by this?
>
> https://github.com/apache/httpd/blob/46a9db4c6f9fadca4e362872021fa62a37908ece/server/mpm/event/event.c#L2096-L2101

With PR #294 this specific case shouldn't happen anymore (thanks to
https://github.com/apache/httpd/pull/294/commits/7089813e13bba0f25bd34df4c643cf5878e6e043).
Also, every connection killed by the MPM (timeout, internal error..)
should have an mpm_event:info message (AH10380), do you see any in
your logs Graham?

What might happen still is that a kept-alive connection gets closed by
httpd, after KeepAliveTimeout usually but also as soon as httpd gets
short in worker threads
(https://github.com/apache/httpd/blob/trunk/server/mpm/event/event.c#L2260-L2262),
and in both cases I'm not sure ab wouldn't report the same error
anyway..

With the latest version (sorry I keep updating this PR), I have no
mpm_event:info message (using "LogLevel info ssl:warn"), and ab
reports some "Failed length" requests:
```
$ bin/ab -k -R 20 -n 409600 -c 4096 https://127.0.0.1:40443/index.html
This is ApacheBench, Version 2.3 <$Revision$>
Copyright 1996 Adam Twiss, Zeus Technology Ltd,
http://web.archive.org/web/20000304112933/http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 40960 requests
Completed 81920 requests
Completed 122880 requests
Completed 163840 requests
Completed 204800 requests
Completed 245760 requests
Completed 286720 requests
Completed 327680 requests
Completed 368640 requests
Completed 409600 requests
Finished 409600 requests

Server Software:        Apache/2.5.1-dev
Server Hostname:        127.0.0.1
Server Port:            40443
SSL/TLS Protocol:       TLSv1.2,ECDHE-RSA-AES256-GCM-SHA384,2048,256
Server Temp Key:        X25519 253 bits

Document Path:          /index.html
Document Length:        321 bytes

Concurrency Level:      4096
Concurrency achieved:   4096
Rampup delay:           20 [ms]
Time taken for tests:   106.912 seconds
Complete requests:      409600
Failed requests:        8517
   (Connect: 0, Receive: 0, Length: 8517, Exceptions: 0)
Keep-Alive requests:    396304
Total transferred:      249548361 bytes
HTML transferred:       128820510 bytes
Requests per second:    3831.19 [#/sec] (mean)
Time per request:       1069.118 [ms] (mean)
Time per request:       0.261 [ms] (mean, across all concurrent requests)
Transfer rate:          2279.44 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   72 480.4      0    7428
Processing:     0  580 543.7    442    6290
Waiting:        0  562 541.2    415    6271
Total:          0  652 766.9    464    9050

Percentage of the requests served within a certain time (ms)
  50%    464
  66%    794
  75%    995
  80%   1083
  90%   1268
  95%   1632
  98%   2831
  99%   4490
 100%   9050 (longest request)
```

This is on my laptop with full-throttle cpu/fans during the test, so
the above results are not really exciting..
FWIW,  the MPM setting have enough processes/threads for the load:
```
    StartServers            1
    ServerLimit             1000
    ThreadLimit             50
    ThreadsPerChild         50
    MinSpareThreads         400
    MaxSpareThreads         1000
    MaxRequestWorkers       5000
```

The "length" errors reported by ab show like this in httpd logs
(LogLevel info mpm_event:trace6 ssl:debug):
```
[Wed Feb 09 15:15:44.184365 2022] [mpm_event:trace1] [pid 2489139:tid
139983741224512] event.c(2139): All workers are busy or dying, will
shutdown 1 keep-alive connections
[Wed Feb 09 15:15:44.184373 2022] [mpm_event:trace6] [pid 2489139:tid
139983741224512] event.c(992): [client 127.0.0.1:47568] deferring
close for connection
60e00017e100:60700001b1b0:26:CHECK_REQUEST_LINE_READABLE
[Wed Feb 09 15:15:44.184393 2022] [mpm_event:trace6] [pid 2489139:tid
139984080422464] event.c(2806): [client 127.0.0.1:47568] deferred
close for connection 60e00017e100:60700001b1b0:26:LINGER
[Wed Feb 09 15:15:44.184399 2022] [mpm_event:trace6] [pid 2489139:tid
139984080422464] event.c(1366): [client 127.0.0.1:47568] processing
connection 60e00017e100:60700001b1b0:26:LINGER
[Wed Feb 09 15:15:44.184411 2022] [mpm_event:trace6] [pid 2489139:tid
139984080422464] event.c(2030): [client 127.0.0.1:47568] lingering
close for connection 60e00017e100:60700001b1b0:26:LINGER
[Wed Feb 09 15:15:44.184464 2022] [ssl:debug] [pid 2489139:tid
139984080422464] ssl_engine_io.c(1209): [client 127.0.0.1:47568]
AH02001: Connection closed to child 260 with standard shutdown (server
localhost:40443)
[Wed Feb 09 15:15:44.189968 2022] [mpm_event:trace6] [pid 2489139:tid
139983741224512] event.c(2371): [client 127.0.0.1:47568] polled
connection 60e00017e100:60700001b1b0:26:LINGER_SHORT
[Wed Feb 09 15:15:44.190262 2022] [mpm_event:trace6] [pid 2489139:tid
139983877019200] event.c(1366): [client 127.0.0.1:47568] processing
connection 60e00017e100:60700001b1b0:26:LINGER_SHORT
[Wed Feb 09 15:15:44.190273 2022] [mpm_event:trace6] [pid 2489139:tid
139983877019200] event.c(2030): [client 127.0.0.1:47568] lingering
close for connection 60e00017e100:60700001b1b0:26:LINGER_SHORT
[Wed Feb 09 15:15:44.190283 2022] [mpm_event:trace6] [pid 2489139:tid
139983877019200] event.c(1023): [client 127.0.0.1:47568] closing
connection 60e00017e100:60700001b1b0:26:LINGER_SHORT at
process_lingering_close:2074
```
(full log attached for [client 127.0.0.1:47568], I got the client port
by using the attached ab patch too).


So ab is (appropriately?) reporting errors for kept-alive connections
that had to be shutdown earlier than KeepAliveTimeout, although I
suspect that it would report the same after the KeepAliveTimeout.


Regards;
Yann.

Re: mpm event assertion failures

Posted by Ruediger Pluem <rp...@apache.org>.

On 2/9/22 1:25 PM, Graham Leggett wrote:
> On 08 Feb 2022, at 19:01, Yann Ylavic <ylavic.dev@gmail.com <ma...@gmail.com>> wrote:
> 
>>> The most concurrent requests I can get out of MacOS appears to be roughly 2000 concurrent requests before “connection reset by
>>> peer” kills the test.
>>>
>>> One small detail I have uncovered is that a small percentage of requests fail, caused by httpd gracefully shutting the
>>> connection down before returning a response. Stopping ab in a debugger confirms that openssl returns SSL_ERROR_ZERO_RETURN on
>>> read, which is what openssl does when the other side gracefully triggers close notify.
>>>
>>> Is this something anyone has seen before while I go digging?
>>
>> I tried with ab too and indeed there was some (dead-)locking issue at
>> some point, could you please retry with the latest pushes I just made
>> to the PR?
> 
> I tried with the latest patch, then I tried with no patch (vanilla trunk) and got the same results.
> 
> Working backwards looking for graceful attempts to shut down the SSL connection, I found this:
> 
> ::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [info] [pid 8747] mod_ssl.c(681): [client ::1:56237] AH01964: Connection to child
> 29 established (server localhost:443)
> ::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] ssl_engine_kernel.c(2402): [client ::1:56237] AH02043: SSL
> virtual host for servername localhost found
> ::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] ssl_engine_kernel.c(2262): [client ::1:56237] AH02041: Protocol:
> TLSv1.2, Cipher: ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)
> ::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] ssl_engine_kernel.c(415): [client ::1:56237] AH02034: Initial
> (No.1) HTTPS request received for child 29 (server localhost:443)
> ::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] mod_authz_core.c(843): [client ::1:56237] AH01628: authorization
> result: granted (no directives)
> ::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] ssl_engine_kernel.c(415): [client ::1:56237] AH02034: Subsequent
> (No.2) HTTPS request received for child 27 (server localhost:443)
> ::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] mod_authz_core.c(843): [client ::1:56237] AH01628: authorization
> result: granted (no directives)
> ::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] ssl_engine_kernel.c(415): [client ::1:56237] AH02034: Subsequent
> (No.3) HTTPS request received for child 37 (server localhost:443)
> ::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] mod_authz_core.c(843): [client ::1:56237] AH01628: authorization
> result: granted (no directives)
> ::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] ssl_engine_io.c(1184): [client ::1:56237] AH02001: Connection
> closed to child 29 with standard shutdown (server localhost:443)
> 
> It seems reasonably normal, except what looks like is happening is when "Connection closed to child 29 with standard shutdown” is
> run, this seems to happen before a response is sent to the client.
> 
> ab then goes “that’s weird, I was trying to read a response, but got a connection closed instead”, and marks that request as failed.
> 
> This is limited to keepalive requests, and happens after a number of keepalive requests have been correctly handled.

Probably you get hit by this?

https://github.com/apache/httpd/blob/46a9db4c6f9fadca4e362872021fa62a37908ece/server/mpm/event/event.c#L2096-L2101

If a client sends a request on a keepalive connection it should be prepared that the connection gets closed without a reply and it
should retry if the request is idempotent. This is how I read RFC7230 6.3.1:

https://datatracker.ietf.org/doc/html/rfc7230#section-6.3.1


Regards

Rüdiger

Re: mpm event assertion failures

Posted by Graham Leggett <mi...@sharp.fm>.
On 08 Feb 2022, at 19:01, Yann Ylavic <yl...@gmail.com> wrote:

>> The most concurrent requests I can get out of MacOS appears to be roughly 2000 concurrent requests before “connection reset by peer” kills the test.
>> 
>> One small detail I have uncovered is that a small percentage of requests fail, caused by httpd gracefully shutting the connection down before returning a response. Stopping ab in a debugger confirms that openssl returns SSL_ERROR_ZERO_RETURN on read, which is what openssl does when the other side gracefully triggers close notify.
>> 
>> Is this something anyone has seen before while I go digging?
> 
> I tried with ab too and indeed there was some (dead-)locking issue at
> some point, could you please retry with the latest pushes I just made
> to the PR?

I tried with the latest patch, then I tried with no patch (vanilla trunk) and got the same results.

Working backwards looking for graceful attempts to shut down the SSL connection, I found this:

::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [info] [pid 8747] mod_ssl.c(681): [client ::1:56237] AH01964: Connection to child 29 established (server localhost:443)
::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] ssl_engine_kernel.c(2402): [client ::1:56237] AH02043: SSL virtual host for servername localhost found
::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] ssl_engine_kernel.c(2262): [client ::1:56237] AH02041: Protocol: TLSv1.2, Cipher: ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)
::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] ssl_engine_kernel.c(415): [client ::1:56237] AH02034: Initial (No.1) HTTPS request received for child 29 (server localhost:443)
::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] mod_authz_core.c(843): [client ::1:56237] AH01628: authorization result: granted (no directives)
::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] ssl_engine_kernel.c(415): [client ::1:56237] AH02034: Subsequent (No.2) HTTPS request received for child 27 (server localhost:443)
::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] mod_authz_core.c(843): [client ::1:56237] AH01628: authorization result: granted (no directives)
::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] ssl_engine_kernel.c(415): [client ::1:56237] AH02034: Subsequent (No.3) HTTPS request received for child 37 (server localhost:443)
::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] mod_authz_core.c(843): [client ::1:56237] AH01628: authorization result: granted (no directives)
::1:56237 ::1:56237 [Wed Feb 09 09:52:21 2022] [debug] [pid 8747] ssl_engine_io.c(1184): [client ::1:56237] AH02001: Connection closed to child 29 with standard shutdown (server localhost:443)

It seems reasonably normal, except what looks like is happening is when "Connection closed to child 29 with standard shutdown” is run, this seems to happen before a response is sent to the client.

ab then goes “that’s weird, I was trying to read a response, but got a connection closed instead”, and marks that request as failed.

This is limited to keepalive requests, and happens after a number of keepalive requests have been correctly handled.

Regards,
Graham
—


Re: mpm event assertion failures

Posted by Yann Ylavic <yl...@gmail.com>.
On Tue, Feb 8, 2022 at 2:15 PM Graham Leggett <mi...@sharp.fm> wrote:
>
> On 07 Feb 2022, at 18:13, Yann Ylavic <yl...@gmail.com> wrote:
>
> All green: https://app.travis-ci.com/github/apache/httpd/builds/246021482  \o/
>
>
> I’ve been load testing these changes with the fixed trunk version of ab

Thanks!

> The most concurrent requests I can get out of MacOS appears to be roughly 2000 concurrent requests before “connection reset by peer” kills the test.
>
> One small detail I have uncovered is that a small percentage of requests fail, caused by httpd gracefully shutting the connection down before returning a response. Stopping ab in a debugger confirms that openssl returns SSL_ERROR_ZERO_RETURN on read, which is what openssl does when the other side gracefully triggers close notify.
>
> Is this something anyone has seen before while I go digging?

I tried with ab too and indeed there was some (dead-)locking issue at
some point, could you please retry with the latest pushes I just made
to the PR?

Regards;
Yann.

Re: mpm event assertion failures

Posted by Graham Leggett <mi...@sharp.fm>.
On 07 Feb 2022, at 18:13, Yann Ylavic <yl...@gmail.com> wrote:

> All green: https://app.travis-ci.com/github/apache/httpd/builds/246021482 <https://app.travis-ci.com/github/apache/httpd/builds/246021482>  \o/

I’ve been load testing these changes with the fixed trunk version of ab, most recently modified at have a ramp delay to stop the OS kicking in and protecting itself from denial of service. The most concurrent requests I can get out of MacOS appears to be roughly 2000 concurrent requests before “connection reset by peer” kills the test.

One small detail I have uncovered is that a small percentage of requests fail, caused by httpd gracefully shutting the connection down before returning a response. Stopping ab in a debugger confirms that openssl returns SSL_ERROR_ZERO_RETURN on read, which is what openssl does when the other side gracefully triggers close notify.

Is this something anyone has seen before while I go digging?

Little-Net:~ root# ulimit -n 10240; /tmp/httpd-trunk/bin/ab -k -R 20 -n 4096000 -c 4096 https://localhost:9443/blah.txt
This is ApacheBench, Version 2.3 <$Revision: 1897866 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://web.archive.org/web/20000304112933/http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 409600 requests

Test aborted after 10 failures

apr_socket_connect(): Connection reset by peer (54)
Total of 498014 requests completed


Server Software:        Apache/2.5.1-dev
Server Hostname:        localhost
Server Port:            9443
SSL/TLS Protocol:       TLSv1.2,ECDHE-RSA-AES256-GCM-SHA384,2048,256
Server Temp Key:        X25519 253 bits
TLS Server Name:        localhost

Document Path:          /blah.txt
Document Length:        9 bytes

Concurrency Level:      4096
Concurrency achieved:   2028
Rampup delay:           20 [ms]
Time taken for tests:   40.629 seconds
Complete requests:      498014
Failed requests:        13102
   (Connect: 1, Receive: 0, Length: 13101, Exceptions: 0)
Keep-Alive requests:    482963
Total transferred:      135219777 bytes
HTML transferred:       4364253 bytes
Requests per second:    12257.69 [#/sec] (mean)
Time per request:       334.158 [ms] (mean)
Time per request:       0.082 [ms] (mean, across all concurrent requests)
Transfer rate:          3250.18 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   10  60.8      0     847
Processing:     0   73  70.5     54     611
Waiting:        0   70  69.9     52     487
Total:          0   82  96.4     56    1192

Percentage of the requests served within a certain time (ms)
  50%     56
  66%     91
  75%    109
  80%    125
  90%    171
  95%    224
  98%    410
  99%    485
 100%   1192 (longest request)

Regards,
Graham
—


Re: mpm event assertion failures

Posted by Stefan Eissing <st...@eissing.org>.

> Am 07.02.2022 um 17:13 schrieb Yann Ylavic <yl...@gmail.com>:
> 
> On Mon, Feb 7, 2022 at 3:41 PM Stefan Eissing <st...@eissing.org> wrote:
>> 
>> 
>> 
>>> Am 07.02.2022 um 14:44 schrieb Stefan Eissing <st...@eissing.org>:
>>> 
>>> 
>>> 
>>>> Am 07.02.2022 um 13:47 schrieb Yann Ylavic <yl...@gmail.com>:
>>>> 
>>>> On Mon, Feb 7, 2022 at 1:29 PM Yann Ylavic <yl...@gmail.com> wrote:
>>>>> 
>>>>> On Mon, Feb 7, 2022 at 1:01 PM Stefan Eissing <st...@eissing.org> wrote:
>>>>>> 
>>>> []
>>>>> 
>>>>> there are still failures for
>>>>> mod_md still I haven't looked at (I think I don't have all the mod_md
>>>>> dependencies to test on my machine)..
>>>> 
>>>> Namely this failure:
>>>> https://app.travis-ci.com/github/apache/httpd/jobs/558512606#L2522
>>>> Does it ring a bell for you?
>>> 
>>> Hmm, no, but I can have a look. There might be some timing involved...
>> 
>> Should be fixed in r1897819.
> 
> All green: https://app.travis-ci.com/github/apache/httpd/builds/246021482  \o/

👍🏻

Re: mpm event assertion failures

Posted by Yann Ylavic <yl...@gmail.com>.
On Mon, Feb 7, 2022 at 3:41 PM Stefan Eissing <st...@eissing.org> wrote:
>
>
>
> > Am 07.02.2022 um 14:44 schrieb Stefan Eissing <st...@eissing.org>:
> >
> >
> >
> >> Am 07.02.2022 um 13:47 schrieb Yann Ylavic <yl...@gmail.com>:
> >>
> >> On Mon, Feb 7, 2022 at 1:29 PM Yann Ylavic <yl...@gmail.com> wrote:
> >>>
> >>> On Mon, Feb 7, 2022 at 1:01 PM Stefan Eissing <st...@eissing.org> wrote:
> >>>>
> >> []
> >>>
> >>> there are still failures for
> >>> mod_md still I haven't looked at (I think I don't have all the mod_md
> >>> dependencies to test on my machine)..
> >>
> >> Namely this failure:
> >> https://app.travis-ci.com/github/apache/httpd/jobs/558512606#L2522
> >> Does it ring a bell for you?
> >
> > Hmm, no, but I can have a look. There might be some timing involved...
>
> Should be fixed in r1897819.

All green: https://app.travis-ci.com/github/apache/httpd/builds/246021482  \o/

Thanks!

Re: mpm event assertion failures

Posted by Stefan Eissing <st...@eissing.org>.

> Am 07.02.2022 um 14:44 schrieb Stefan Eissing <st...@eissing.org>:
> 
> 
> 
>> Am 07.02.2022 um 13:47 schrieb Yann Ylavic <yl...@gmail.com>:
>> 
>> On Mon, Feb 7, 2022 at 1:29 PM Yann Ylavic <yl...@gmail.com> wrote:
>>> 
>>> On Mon, Feb 7, 2022 at 1:01 PM Stefan Eissing <st...@eissing.org> wrote:
>>>> 
>> []
>>> 
>>> there are still failures for
>>> mod_md still I haven't looked at (I think I don't have all the mod_md
>>> dependencies to test on my machine)..
>> 
>> Namely this failure:
>> https://app.travis-ci.com/github/apache/httpd/jobs/558512606#L2522
>> Does it ring a bell for you?
> 
> Hmm, no, but I can have a look. There might be some timing involved...

Should be fixed in r1897819.

> 
>> 
>>> 
>>> Cheers;
>>> Yann.


Re: mpm event assertion failures

Posted by Stefan Eissing <st...@eissing.org>.

> Am 07.02.2022 um 13:47 schrieb Yann Ylavic <yl...@gmail.com>:
> 
> On Mon, Feb 7, 2022 at 1:29 PM Yann Ylavic <yl...@gmail.com> wrote:
>> 
>> On Mon, Feb 7, 2022 at 1:01 PM Stefan Eissing <st...@eissing.org> wrote:
>>> 
> []
>> 
>> there are still failures for
>> mod_md still I haven't looked at (I think I don't have all the mod_md
>> dependencies to test on my machine)..
> 
> Namely this failure:
> https://app.travis-ci.com/github/apache/httpd/jobs/558512606#L2522
> Does it ring a bell for you?

Hmm, no, but I can have a look. There might be some timing involved...

> 
>> 
>> Cheers;
>> Yann.


Re: mpm event assertion failures

Posted by Yann Ylavic <yl...@gmail.com>.
On Mon, Feb 7, 2022 at 1:29 PM Yann Ylavic <yl...@gmail.com> wrote:
>
> On Mon, Feb 7, 2022 at 1:01 PM Stefan Eissing <st...@eissing.org> wrote:
> >
[]
>
> there are still failures for
> mod_md still I haven't looked at (I think I don't have all the mod_md
> dependencies to test on my machine)..

Namely this failure:
https://app.travis-ci.com/github/apache/httpd/jobs/558512606#L2522
Does it ring a bell for you?

>
> Cheers;
> Yann.

Re: mpm event assertion failures

Posted by Yann Ylavic <yl...@gmail.com>.
On Mon, Feb 7, 2022 at 1:01 PM Stefan Eissing <st...@eissing.org> wrote:
>
> > Am 07.02.2022 um 12:46 schrieb Yann Ylavic <yl...@gmail.com>:
> >>
> >> The assertion failure is due to mpm_event closing all the workers'
> >> sockets forcibly [1] on ungraceful shutdown/restart, while the socket
> >> is still handled by h2, thus when h2 gives the connection back to the
> >> mpm fr lingering close it fails.
>
> Wow, you have been busy! Can I apply the PR diff to trunk for a test drive on my machine?

Yes, the PR is based off trunk.

I've just added a fix for beam cleanups because test_h2_500_20 was
failing sporadically on travis, and there are still failures for
mod_md still I haven't looked at (I think I don't have all the mod_md
dependencies to test on my machine)..

Cheers;
Yann.

Re: mpm event assertion failures

Posted by Stefan Eissing <st...@eissing.org>.

> Am 07.02.2022 um 12:46 schrieb Yann Ylavic <yl...@gmail.com>:
> 
> On Mon, Feb 7, 2022 at 12:41 PM Yann Ylavic <yl...@gmail.com> wrote:
>> 
>> On Tue, Jan 25, 2022 at 1:12 PM Stefan Eissing <st...@eissing.org> wrote:
>>> 
>>> Also, while running the http2 test suite, I get repeated assert failures in event.c:1230
>>> 
>>> if (rv != APR_SUCCESS && !APR_STATUS_IS_EEXIST(rv)) {
>>> ->  AP_DEBUG_ASSERT(0);
>>>    TO_QUEUE_REMOVE(cs->sc->wc_q, cs);
>>>    apr_thread_mutex_unlock(timeout_mutex);
>>>    ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, APLOGNO(03465)
>>>                 "process_socket: apr_pollset_add failure for "
>>>                 "write completion");
>>>    close_connection(cs);
>>>    signal_threads(ST_GRACEFUL);
>>> }
>>> 
>>> Seems something is fishy with the recent changes.
>> 
>> 
>> The assertion failure is due to mpm_event closing all the workers'
>> sockets forcibly [1] on ungraceful shutdown/restart, while the socket
>> is still handled by h2, thus when h2 gives the connection back to the
>> mpm fr lingering close it fails.

Wow, you have been busy! Can I apply the PR diff to trunk for a test drive on my machine?

>> 
>> This is fixed in PR #294 by [2].
>> 
>> [1] https://github.com/apache/httpd/pull/294/files#diff-0f7c762a65575c89143d8ab894ec9d79e6f2f26aca2c4e4c102e129043683310L594
>> [2] https://github.com/apache/httpd/pull/294/files#diff-0f7c762a65575c89143d8ab894ec9d79e6f2f26aca2c4e4c102e129043683310R1143
> 
> With the right links..
> 
> [1] https://github.com/apache/httpd/pull/294/commits/9996178dfdb01d41ae26a196109241e16cc041a6#diff-0f7c762a65575c89143d8ab894ec9d79e6f2f26aca2c4e4c102e129043683310L597
> [2] https://github.com/apache/httpd/pull/294/commits/9996178dfdb01d41ae26a196109241e16cc041a6#diff-0f7c762a65575c89143d8ab894ec9d79e6f2f26aca2c4e4c102e129043683310R1070
> 
>> 
>> Regards;
>> Yann.


Re: mpm event assertion failures

Posted by Yann Ylavic <yl...@gmail.com>.
On Mon, Feb 7, 2022 at 12:41 PM Yann Ylavic <yl...@gmail.com> wrote:
>
> On Tue, Jan 25, 2022 at 1:12 PM Stefan Eissing <st...@eissing.org> wrote:
> >
> > Also, while running the http2 test suite, I get repeated assert failures in event.c:1230
> >
> > if (rv != APR_SUCCESS && !APR_STATUS_IS_EEXIST(rv)) {
> > ->  AP_DEBUG_ASSERT(0);
> >     TO_QUEUE_REMOVE(cs->sc->wc_q, cs);
> >     apr_thread_mutex_unlock(timeout_mutex);
> >     ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, APLOGNO(03465)
> >                  "process_socket: apr_pollset_add failure for "
> >                  "write completion");
> >     close_connection(cs);
> >     signal_threads(ST_GRACEFUL);
> > }
> >
> > Seems something is fishy with the recent changes.
>
>
> The assertion failure is due to mpm_event closing all the workers'
> sockets forcibly [1] on ungraceful shutdown/restart, while the socket
> is still handled by h2, thus when h2 gives the connection back to the
> mpm fr lingering close it fails.
>
> This is fixed in PR #294 by [2].
>
> [1] https://github.com/apache/httpd/pull/294/files#diff-0f7c762a65575c89143d8ab894ec9d79e6f2f26aca2c4e4c102e129043683310L594
> [2] https://github.com/apache/httpd/pull/294/files#diff-0f7c762a65575c89143d8ab894ec9d79e6f2f26aca2c4e4c102e129043683310R1143

With the right links..

[1] https://github.com/apache/httpd/pull/294/commits/9996178dfdb01d41ae26a196109241e16cc041a6#diff-0f7c762a65575c89143d8ab894ec9d79e6f2f26aca2c4e4c102e129043683310L597
[2] https://github.com/apache/httpd/pull/294/commits/9996178dfdb01d41ae26a196109241e16cc041a6#diff-0f7c762a65575c89143d8ab894ec9d79e6f2f26aca2c4e4c102e129043683310R1070

>
> Regards;
> Yann.

Re: mpm event assertion failures

Posted by Yann Ylavic <yl...@gmail.com>.
On Tue, Jan 25, 2022 at 1:12 PM Stefan Eissing <st...@eissing.org> wrote:
>
> Also, while running the http2 test suite, I get repeated assert failures in event.c:1230
>
> if (rv != APR_SUCCESS && !APR_STATUS_IS_EEXIST(rv)) {
> ->  AP_DEBUG_ASSERT(0);
>     TO_QUEUE_REMOVE(cs->sc->wc_q, cs);
>     apr_thread_mutex_unlock(timeout_mutex);
>     ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, APLOGNO(03465)
>                  "process_socket: apr_pollset_add failure for "
>                  "write completion");
>     close_connection(cs);
>     signal_threads(ST_GRACEFUL);
> }
>
> Seems something is fishy with the recent changes.


The assertion failure is due to mpm_event closing all the workers'
sockets forcibly [1] on ungraceful shutdown/restart, while the socket
is still handled by h2, thus when h2 gives the connection back to the
mpm fr lingering close it fails.

This is fixed in PR #294 by [2].

[1] https://github.com/apache/httpd/pull/294/files#diff-0f7c762a65575c89143d8ab894ec9d79e6f2f26aca2c4e4c102e129043683310L594
[2] https://github.com/apache/httpd/pull/294/files#diff-0f7c762a65575c89143d8ab894ec9d79e6f2f26aca2c4e4c102e129043683310R1143


Regards;
Yann.

Re: mpm event assertion failures

Posted by Stefan Eissing <st...@eissing.org>.

> Am 07.02.2022 um 12:19 schrieb Graham Leggett <mi...@sharp.fm>:
> 
> On 07 Feb 2022, at 12:35, Stefan Eissing <st...@eissing.org> wrote:
> 
>>> There are two parts that hook into the process_connection hook, the code you’ve cited above, and this code:
>>> 
>>> void h2_c2_register_hooks(void)
>>> {
>>>    /* When the connection processing actually starts, we might
>>>     * take over, if the connection is for a h2 stream.
>>>     */
>>>    ap_hook_process_connection(h2_c2_hook_process,
>>>                               NULL, NULL, APR_HOOK_FIRST);
>>> 
>>> Looks like this code is running before mod_ssl somehow.
>>> 
>>> Is there a way to run the httpd under test in either lldb or gdb?
>> 
>> The names "h2_c1..." and "h2_c2..." indicate, that the former operates on "primary" connections, e.g. the ones from a client where SSL is applied, and "secondary" connections (c->master != NULL), e.g. where h2 requests are processed and SSL is not involved.
> 
> In theory it’s all the same hook though, so even though h2_c2_hook_process() is standing out of the way of anything not a secondary connection, it’s still running before mod_ssl, and it still throws away the AGAIN, leaving mod_ssl in an undefined state.

I do not understand. h2_c2_process returns DECLINED on a c1 connection (!c->master). How does that mess with any return code a subsequent hook returns?
> 
> I’m assuming h2_c2_hook_process just wants to run before h2_c1_hook_process_connection?

No, it definitely wants to prevent any other process hook from running *if and only if* it processes the connection itself. It does not want any SSL module to insert its filters, specifically.

> 
> I just tried this patch on rawhide (where I’m getting success with the http2 tests) and we still work:
> 
> Index: modules/http2/h2_c1.c
> ===================================================================
> --- modules/http2/h2_c1.c	(revision 1897807)
> +++ modules/http2/h2_c1.c	(working copy)
> @@ -312,6 +312,7 @@
>  
>  static const char* const mod_ssl[]        = { "mod_ssl.c", NULL};
>  static const char* const mod_reqtimeout[] = { "mod_ssl.c", "mod_reqtimeout.c", NULL};
> +static const char* const mod_h2_c2[]      = { "mod_ssl.c", "mod_reqtimeout.c", "h2_c2.c", NULL};
>  
>  void h2_c1_register_hooks(void)
>  {
> @@ -322,7 +323,7 @@
>       * a chance to take over before it.
>       */
>      ap_hook_process_connection(h2_c1_hook_process_connection,
> -                               mod_reqtimeout, NULL, APR_HOOK_LAST);
> +                               mod_h2_c2, NULL, APR_HOOK_LAST);
>  
>      /* One last chance to properly say goodbye if we have not done so
>       * already. */
> Index: modules/http2/h2_c2.c
> ===================================================================
> --- modules/http2/h2_c2.c	(revision 1897807)
> +++ modules/http2/h2_c2.c	(working copy)
> @@ -707,7 +707,7 @@
>       * take over, if the connection is for a h2 stream.
>       */
>      ap_hook_process_connection(h2_c2_hook_process,
> -                               NULL, NULL, APR_HOOK_FIRST);
> +                               NULL, NULL, APR_HOOK_LAST);
>      /* We need to manipulate the standard HTTP/1.1 protocol filters and
>       * install our own. This needs to be done very early. */
>      ap_hook_post_read_request(h2_c2_hook_post_read_request, NULL, NULL, APR_HOOK_REALLY_FIRST);
> 
> Regards,
> Graham
> —


Re: mpm event assertion failures

Posted by Graham Leggett <mi...@sharp.fm>.
On 07 Feb 2022, at 12:35, Stefan Eissing <st...@eissing.org> wrote:

>> There are two parts that hook into the process_connection hook, the code you’ve cited above, and this code:
>> 
>> void h2_c2_register_hooks(void)
>> {
>>    /* When the connection processing actually starts, we might
>>     * take over, if the connection is for a h2 stream.
>>     */
>>    ap_hook_process_connection(h2_c2_hook_process,
>>                               NULL, NULL, APR_HOOK_FIRST);
>> 
>> Looks like this code is running before mod_ssl somehow.
>> 
>> Is there a way to run the httpd under test in either lldb or gdb?
> 
> The names "h2_c1..." and "h2_c2..." indicate, that the former operates on "primary" connections, e.g. the ones from a client where SSL is applied, and "secondary" connections (c->master != NULL), e.g. where h2 requests are processed and SSL is not involved.

In theory it’s all the same hook though, so even though h2_c2_hook_process() is standing out of the way of anything not a secondary connection, it’s still running before mod_ssl, and it still throws away the AGAIN, leaving mod_ssl in an undefined state.

I’m assuming h2_c2_hook_process just wants to run before h2_c1_hook_process_connection?

I just tried this patch on rawhide (where I’m getting success with the http2 tests) and we still work:

Index: modules/http2/h2_c1.c
===================================================================
--- modules/http2/h2_c1.c	(revision 1897807)
+++ modules/http2/h2_c1.c	(working copy)
@@ -312,6 +312,7 @@
 
 static const char* const mod_ssl[]        = { "mod_ssl.c", NULL};
 static const char* const mod_reqtimeout[] = { "mod_ssl.c", "mod_reqtimeout.c", NULL};
+static const char* const mod_h2_c2[]      = { "mod_ssl.c", "mod_reqtimeout.c", "h2_c2.c", NULL};
 
 void h2_c1_register_hooks(void)
 {
@@ -322,7 +323,7 @@
      * a chance to take over before it.
      */
     ap_hook_process_connection(h2_c1_hook_process_connection,
-                               mod_reqtimeout, NULL, APR_HOOK_LAST);
+                               mod_h2_c2, NULL, APR_HOOK_LAST);
 
     /* One last chance to properly say goodbye if we have not done so
      * already. */
Index: modules/http2/h2_c2.c
===================================================================
--- modules/http2/h2_c2.c	(revision 1897807)
+++ modules/http2/h2_c2.c	(working copy)
@@ -707,7 +707,7 @@
      * take over, if the connection is for a h2 stream.
      */
     ap_hook_process_connection(h2_c2_hook_process,
-                               NULL, NULL, APR_HOOK_FIRST);
+                               NULL, NULL, APR_HOOK_LAST);
     /* We need to manipulate the standard HTTP/1.1 protocol filters and
      * install our own. This needs to be done very early. */
     ap_hook_post_read_request(h2_c2_hook_post_read_request, NULL, NULL, APR_HOOK_REALLY_FIRST);

Regards,
Graham
—


Re: mpm event assertion failures

Posted by Stefan Eissing <st...@eissing.org>.

> Am 07.02.2022 um 11:31 schrieb Graham Leggett <mi...@sharp.fm>:
> 
> On 07 Feb 2022, at 12:18, Stefan Eissing <st...@eissing.org> wrote:
> 
>>>> Is the http2 code doing anything to work around mod_ssl trying to read, failing, throwing away the error, and then pretending nothing happened?
>>> 
>>> The http2 code doesn't try to work around mod_ssl, instead it does the same as mod_ssl, which is that it performs an operation but throws away the error:
>>> 
>>> https://github.com/apache/httpd/blob/1598f7aebd59acc7494389a3903a33c5e38a5460/modules/http2/h2_c2.c#L632
>>> 
>>> This hook is sorted APR_HOOK_FIRST, which means h2_c2_hook_process() runs first, then passes the connection to mod_ssl, which then returns AGAIN, but AGAIN is now thrown away inside h2_c2_hook_process(), and now we’re off the rails from this point on and we can expect our socket to be stuck in a weird state.
>>> 
>>> The http1 code has the same problem, but runs APR_HOOK_LAST, which means mod_ssl’s handshake is completely done before http1 touches the connection.
>>> 
>>> I think to fix this test, we need to make sure http2 runs after mod_ssl.
>> 
>> It does.
>> 
>> h2_c1.c:
>> 
>> static const char* const mod_reqtimeout[] = { "mod_ssl.c", "mod_reqtimeout.c", NULL};
>> 
>> void h2_c1_register_hooks(void)
>> {
>>    /* Our main processing needs to run quite late. Definitely after mod_ssl,
>>     * as we need its connection filters, but also before reqtimeout as its
>>     * method of timeouts is specific to HTTP/1.1 (as of now).
>>     * The core HTTP/1 processing run as REALLY_LAST, so we will have
>>     * a chance to take over before it.
>>     */
>>    ap_hook_process_connection(h2_c1_hook_process_connection,
>>                               mod_reqtimeout, NULL, APR_HOOK_LAST);
>>    ...
>> 
>> 
>> In my understanding this is how it should work. When mod_ssl's process_connection fails, it should return OK to prevent further hooks to run.
>> 
>> AP_IMPLEMENT_HOOK_RUN_FIRST(int,process_connection,(conn_rec *c),(c),DECLINED)
>> 
>> process_connection is a RUN_FIRST. So the first hook that returns OK, terminates it.
>> 
>> If mod_ssl returns OK in case of handshake errors, the connection is done. That is my read of it.
> 
> There are two parts that hook into the process_connection hook, the code you’ve cited above, and this code:
> 
> void h2_c2_register_hooks(void)
> {
>     /* When the connection processing actually starts, we might
>      * take over, if the connection is for a h2 stream.
>      */
>     ap_hook_process_connection(h2_c2_hook_process,
>                                NULL, NULL, APR_HOOK_FIRST);
> 
> Looks like this code is running before mod_ssl somehow.
> 
> Is there a way to run the httpd under test in either lldb or gdb?

The names "h2_c1..." and "h2_c2..." indicate, that the former operates on "primary" connections, e.g. the ones from a client where SSL is applied, and "secondary" connections (c->master != NULL), e.g. where h2 requests are processed and SSL is not involved.

> 
> Regards,
> Graham
> —
> 


Re: mpm event assertion failures

Posted by Graham Leggett <mi...@sharp.fm>.
On 07 Feb 2022, at 12:18, Stefan Eissing <st...@eissing.org> wrote:

>>> Is the http2 code doing anything to work around mod_ssl trying to read, failing, throwing away the error, and then pretending nothing happened?
>> 
>> The http2 code doesn't try to work around mod_ssl, instead it does the same as mod_ssl, which is that it performs an operation but throws away the error:
>> 
>> https://github.com/apache/httpd/blob/1598f7aebd59acc7494389a3903a33c5e38a5460/modules/http2/h2_c2.c#L632
>> 
>> This hook is sorted APR_HOOK_FIRST, which means h2_c2_hook_process() runs first, then passes the connection to mod_ssl, which then returns AGAIN, but AGAIN is now thrown away inside h2_c2_hook_process(), and now we’re off the rails from this point on and we can expect our socket to be stuck in a weird state.
>> 
>> The http1 code has the same problem, but runs APR_HOOK_LAST, which means mod_ssl’s handshake is completely done before http1 touches the connection.
>> 
>> I think to fix this test, we need to make sure http2 runs after mod_ssl.
> 
> It does.
> 
> h2_c1.c:
> 
> static const char* const mod_reqtimeout[] = { "mod_ssl.c", "mod_reqtimeout.c", NULL};
> 
> void h2_c1_register_hooks(void)
> {
>    /* Our main processing needs to run quite late. Definitely after mod_ssl,
>     * as we need its connection filters, but also before reqtimeout as its
>     * method of timeouts is specific to HTTP/1.1 (as of now).
>     * The core HTTP/1 processing run as REALLY_LAST, so we will have
>     * a chance to take over before it.
>     */
>    ap_hook_process_connection(h2_c1_hook_process_connection,
>                               mod_reqtimeout, NULL, APR_HOOK_LAST);
>    ...
> 
> 
> In my understanding this is how it should work. When mod_ssl's process_connection fails, it should return OK to prevent further hooks to run.
> 
> AP_IMPLEMENT_HOOK_RUN_FIRST(int,process_connection,(conn_rec *c),(c),DECLINED)
> 
> process_connection is a RUN_FIRST. So the first hook that returns OK, terminates it.
> 
> If mod_ssl returns OK in case of handshake errors, the connection is done. That is my read of it.

There are two parts that hook into the process_connection hook, the code you’ve cited above, and this code:

void h2_c2_register_hooks(void)
{
    /* When the connection processing actually starts, we might
     * take over, if the connection is for a h2 stream.
     */
    ap_hook_process_connection(h2_c2_hook_process,
                               NULL, NULL, APR_HOOK_FIRST);

Looks like this code is running before mod_ssl somehow.

Is there a way to run the httpd under test in either lldb or gdb?

Regards,
Graham
—


Re: mpm event assertion failures

Posted by Stefan Eissing <st...@eissing.org>.

> Am 06.02.2022 um 23:00 schrieb Graham Leggett <mi...@sharp.fm>:
> 
> On 25 Jan 2022, at 23:25, Graham Leggett <mi...@sharp.fm> wrote:
> 
>> Is the http2 code doing anything to work around mod_ssl trying to read, failing, throwing away the error, and then pretending nothing happened?
> 
> The http2 code doesn't try to work around mod_ssl, instead it does the same as mod_ssl, which is that it performs an operation but throws away the error:
> 
> https://github.com/apache/httpd/blob/1598f7aebd59acc7494389a3903a33c5e38a5460/modules/http2/h2_c2.c#L632
> 
> This hook is sorted APR_HOOK_FIRST, which means h2_c2_hook_process() runs first, then passes the connection to mod_ssl, which then returns AGAIN, but AGAIN is now thrown away inside h2_c2_hook_process(), and now we’re off the rails from this point on and we can expect our socket to be stuck in a weird state.
> 
> The http1 code has the same problem, but runs APR_HOOK_LAST, which means mod_ssl’s handshake is completely done before http1 touches the connection.
> 
> I think to fix this test, we need to make sure http2 runs after mod_ssl.

It does.

h2_c1.c:

static const char* const mod_reqtimeout[] = { "mod_ssl.c", "mod_reqtimeout.c", NULL};

void h2_c1_register_hooks(void)
{
    /* Our main processing needs to run quite late. Definitely after mod_ssl,
     * as we need its connection filters, but also before reqtimeout as its
     * method of timeouts is specific to HTTP/1.1 (as of now).
     * The core HTTP/1 processing run as REALLY_LAST, so we will have
     * a chance to take over before it.
     */
    ap_hook_process_connection(h2_c1_hook_process_connection,
                               mod_reqtimeout, NULL, APR_HOOK_LAST);
    ...


In my understanding this is how it should work. When mod_ssl's process_connection fails, it should return OK to prevent further hooks to run.

AP_IMPLEMENT_HOOK_RUN_FIRST(int,process_connection,(conn_rec *c),(c),DECLINED)

process_connection is a RUN_FIRST. So the first hook that returns OK, terminates it.

If mod_ssl returns OK in case of handshake errors, the connection is done. That is my read of it.

Kind Regards,
Stefan

> Regards,
> Graham
> —
> 


Re: mpm event assertion failures

Posted by Graham Leggett <mi...@sharp.fm>.
On 25 Jan 2022, at 23:25, Graham Leggett <mi...@sharp.fm> wrote:

> Is the http2 code doing anything to work around mod_ssl trying to read, failing, throwing away the error, and then pretending nothing happened?

The http2 code doesn't try to work around mod_ssl, instead it does the same as mod_ssl, which is that it performs an operation but throws away the error:

https://github.com/apache/httpd/blob/1598f7aebd59acc7494389a3903a33c5e38a5460/modules/http2/h2_c2.c#L632

This hook is sorted APR_HOOK_FIRST, which means h2_c2_hook_process() runs first, then passes the connection to mod_ssl, which then returns AGAIN, but AGAIN is now thrown away inside h2_c2_hook_process(), and now we’re off the rails from this point on and we can expect our socket to be stuck in a weird state.

The http1 code has the same problem, but runs APR_HOOK_LAST, which means mod_ssl’s handshake is completely done before http1 touches the connection.

I think to fix this test, we need to make sure http2 runs after mod_ssl.

Regards,
Graham
—


Re: mpm event assertion failures

Posted by Stefan Eissing <st...@eissing.org>.

> Am 25.01.2022 um 22:25 schrieb Graham Leggett <mi...@sharp.fm>:
> 
> On 25 Jan 2022, at 14:11, Stefan Eissing <st...@eissing.org> wrote:
> 
>> Also, while running the http2 test suite, I get repeated assert failures in event.c:1230
>> 
>> if (rv != APR_SUCCESS && !APR_STATUS_IS_EEXIST(rv)) {
>> ->  AP_DEBUG_ASSERT(0);
>>   TO_QUEUE_REMOVE(cs->sc->wc_q, cs);
>>   apr_thread_mutex_unlock(timeout_mutex);
>>   ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, APLOGNO(03465)
>>                "process_socket: apr_pollset_add failure for "
>>                "write completion");
>>   close_connection(cs);
>>   signal_threads(ST_GRACEFUL);
>> }
> 
> One line above is this:
> 
>            rv = apr_pollset_add(event_pollset, &cs->pfd);
> 
> and looking up the log we fail with a bad file descriptor.
> 
> This looks like it’s being triggered by this:
> 
> https://github.com/apache/apr/blob/trunk/poll/unix/poll.c#L194
> 
> which in turn looks like an apr_file_t is being added to the connection. Does that seem familiar?

I do not even parse that statement. What does "added to the connection" mean?

> To explain what’s changed in mod_ssl, a bug has been fixed. In the old mod_ssl, directly after connecting we make one single attempt to read zero bytes in a blocking connection. OpenSSL kicks in and performs reads and writes to finish the handshake. And then if that failed for whatever reason - brokenly - we throw the errors away and pretend nothing happened.
> 
> https://github.com/apache/httpd/blob/2.4.x/modules/ssl/mod_ssl.c#L695
> 
> We then get into the protocol handler, and in http/1.1 we read the now broken connection a second time here:
> 
> https://github.com/apache/httpd/blob/2.4.x/modules/http/http_core.c#L148
> 
> Is the http2 code doing anything to work around mod_ssl trying to read, failing, throwing away the error, and then pretending nothing happened? To fix this behaviour, I suspect whatever you needed to do to work around the mod_ssl bug needs to be undone.

Guys, we have changes in a central part of the server and our CI fails. 
It is not good enough to give other people unspecific homework to fix it. 

Analyze what you broke and if we can help, we'll happily do that. But
you need to give some more details here.

- Stefan

Re: mpm event assertion failures

Posted by Yann Ylavic <yl...@gmail.com>.
On Tue, Jan 25, 2022 at 10:26 PM Graham Leggett <mi...@sharp.fm> wrote:
>
> On 25 Jan 2022, at 14:11, Stefan Eissing <st...@eissing.org> wrote:
>
> > Also, while running the http2 test suite, I get repeated assert failures in event.c:1230
> >
> > if (rv != APR_SUCCESS && !APR_STATUS_IS_EEXIST(rv)) {
> > ->  AP_DEBUG_ASSERT(0);
> >    TO_QUEUE_REMOVE(cs->sc->wc_q, cs);
> >    apr_thread_mutex_unlock(timeout_mutex);
> >    ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, APLOGNO(03465)
> >                 "process_socket: apr_pollset_add failure for "
> >                 "write completion");
> >    close_connection(cs);
> >    signal_threads(ST_GRACEFUL);
> > }
>
> One line above is this:
>
>             rv = apr_pollset_add(event_pollset, &cs->pfd);
>
> and looking up the log we fail with a bad file descriptor.
>
> This looks like it’s being triggered by this:
>
> https://github.com/apache/apr/blob/trunk/poll/unix/poll.c#L194
>
> which in turn looks like an apr_file_t is being added to the connection. Does that seem familiar?

What system is this with !APR_FILES_AS_SOCKETS and apr_pollset using
poll() instead of epoll()?
Is OSX like that? I'd expect it to use kqueue (with APR_FILES_AS_SOCKETS)..

Sorry you will have to debug that, how an apr_file_t different than
the wakeup pipe can end up being apr_pollset_poll()ed and handled like
a connection socket, it doesn't sound familiar to me.

Also it seems that travis triggers this too:
https://app.travis-ci.com/github/apache/httpd/jobs/556994472#L2627
But there it's with apr-1.7.0, so nothing related to latest apr
changes it seems.

>
> To explain what’s changed in mod_ssl, a bug has been fixed.

I wouldn't call it like that..

> In the old mod_ssl, directly after connecting we make one single attempt to read zero bytes in a blocking connection. OpenSSL kicks in and performs reads and writes to finish the handshake. And then if that failed for whatever reason - brokenly - we throw the errors away and pretend nothing happened.
>
> https://github.com/apache/httpd/blob/2.4.x/modules/ssl/mod_ssl.c#L695

Well, the handshake and process_connection hooks in general are run in
blocking mode there.
The expectation (I suppose) is that the next process_connection hook
will catch the error too.

Btw, the new ssl_hook_process_connection() in trunk seems to do that
for AP_FILTER_ERROR still, but not for the other errors.

>
> We then get into the protocol handler, and in http/1.1 we read the now broken connection a second time here:
>
> https://github.com/apache/httpd/blob/2.4.x/modules/http/http_core.c#L148

Yes but is that an issue? It seems that in 2.4.x (and before your
changes in trunk) this actually catches the former error.

Now it seems that you can't make the handshake nonblocking by just
s/APR_BLOCK_READ/APR_NONBLOCK_READ/ and pretend it should work. If it
does not please find the cause (the consequences are shown by the ci
already).

The AH03465 does not trigger on my machine when running the pytest
suites (I even tried with apr-1.7.0), but it triggers on travis so I
suppose there is something with the epoll pollset too?


Regards;
Yann.

Re: mpm event assertion failures

Posted by Graham Leggett <mi...@sharp.fm>.
On 25 Jan 2022, at 14:11, Stefan Eissing <st...@eissing.org> wrote:

> Also, while running the http2 test suite, I get repeated assert failures in event.c:1230
> 
> if (rv != APR_SUCCESS && !APR_STATUS_IS_EEXIST(rv)) {
> ->  AP_DEBUG_ASSERT(0);
>    TO_QUEUE_REMOVE(cs->sc->wc_q, cs);
>    apr_thread_mutex_unlock(timeout_mutex);
>    ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, APLOGNO(03465)
>                 "process_socket: apr_pollset_add failure for "
>                 "write completion");
>    close_connection(cs);
>    signal_threads(ST_GRACEFUL);
> }

One line above is this:

            rv = apr_pollset_add(event_pollset, &cs->pfd);

and looking up the log we fail with a bad file descriptor.

This looks like it’s being triggered by this:

https://github.com/apache/apr/blob/trunk/poll/unix/poll.c#L194

which in turn looks like an apr_file_t is being added to the connection. Does that seem familiar?

To explain what’s changed in mod_ssl, a bug has been fixed. In the old mod_ssl, directly after connecting we make one single attempt to read zero bytes in a blocking connection. OpenSSL kicks in and performs reads and writes to finish the handshake. And then if that failed for whatever reason - brokenly - we throw the errors away and pretend nothing happened.

https://github.com/apache/httpd/blob/2.4.x/modules/ssl/mod_ssl.c#L695

We then get into the protocol handler, and in http/1.1 we read the now broken connection a second time here:

https://github.com/apache/httpd/blob/2.4.x/modules/http/http_core.c#L148

Is the http2 code doing anything to work around mod_ssl trying to read, failing, throwing away the error, and then pretending nothing happened? To fix this behaviour, I suspect whatever you needed to do to work around the mod_ssl bug needs to be undone.

Regards,
Graham
—


Re: mpm event assertion failures

Posted by Yann Ylavic <yl...@gmail.com>.
On Tue, Jan 25, 2022 at 1:12 PM Stefan Eissing <st...@eissing.org> wrote:
>
> Also, while running the http2 test suite, I get repeated assert failures in event.c:1230
>
> if (rv != APR_SUCCESS && !APR_STATUS_IS_EEXIST(rv)) {
> ->  AP_DEBUG_ASSERT(0);
>     TO_QUEUE_REMOVE(cs->sc->wc_q, cs);
>     apr_thread_mutex_unlock(timeout_mutex);
>     ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, APLOGNO(03465)
>                  "process_socket: apr_pollset_add failure for "
>                  "write completion");
>     close_connection(cs);
>     signal_threads(ST_GRACEFUL);
> }
>
> Seems something is fishy with the recent changes.

I'll add that most tests now take 2x (or even 3x) more time to complete.
Graham, something on your radar?


Regards;
Yann.