Return-Path: Delivered-To: apmail-new-httpd-archive@apache.org Received: (qmail 26270 invoked by uid 500); 1 Nov 2000 03:52:14 -0000 Mailing-List: contact new-httpd-help@apache.org; run by ezmlm Precedence: bulk Reply-To: new-httpd@apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list new-httpd@apache.org Received: (qmail 26258 invoked from network); 1 Nov 2000 03:52:14 -0000 Sender: pmarquis Message-ID: <39FF855D.77128BF0@iname.com> Date: Tue, 31 Oct 2000 21:52:13 -0500 From: Paul Marquis X-Mailer: Mozilla 4.72 [en] (X11; U; Linux 2.2.14-5.0 i686) X-Accept-Language: en MIME-Version: 1.0 To: new-httpd@apache.org Subject: Reliable piped logs and select() Linux bug Content-Type: multipart/mixed; boundary="------------8B002184CE22B1389FED5AD8" X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N This is a multi-part message in MIME format. --------------8B002184CE22B1389FED5AD8 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit If this is not the right list, please let me know. I have uncovered what I believe to be a bug with the select() call on Linux when checking for writability of a pipe. This bug, when combined with Reliable Piped Logs, can cause Apache to unnecessarily respawn piped log child processes. The select() call on Linux will report "false negatives" determining if a pipe is writable when any unread data is in the pipe and only when the pipe is completely empty will select() do the right thing. So, for example, after succesfully calling pipe(), if you select() on the write end of the pipe, it will succeed. If you write a single byte and then don't read it from the other end and call select() again, it will fail, but a call to write() will succeed. If you flush the pipe by reading all the data from the other end, select() will succeed again. I don't know if this problem extends beyond pipes. The attached code, which works as expected on FreeBSD and Solaris, demonstrates the bug on Linux. In Apache, the Reliable Piped Logs feature determines that a child process has died by checking if the pipe is writable using select(). If it's not writable, then Apache kills the process and restarts it (I'm basing this on my quick inspection of the Apache documentation and source code). Since, on Linux, select() has the above bug for pipes, Apache will unnecessarily respawn child processes. Until either I'm corrected that this is not a bug, select() on Linux is fixed or there's an Apache workaround (which off the cuff, I don't think is possible), I'm disabling the Reliable Piped Log feature for our web servers. If this is truly a bug, then, to be honest, I don't know how to filter this through the appropriate Linux development channels, though I'm sure some of my co-workers will. Comments? -- Paul Marquis pmarquis@iname.com --------------8B002184CE22B1389FED5AD8 Content-Type: application/octet-stream; name="simple_pipe_test.c" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="simple_pipe_test.c" I2luY2x1ZGUgPHN5cy90aW1lLmg+CiNpbmNsdWRlIDxzeXMvdHlwZXMuaD4KI2luY2x1ZGUg PHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2luY2x1ZGUgPHVuaXN0ZC5oPgojaW5j bHVkZSA8ZXJybm8uaD4KCmludCBtYWluKGludCBhcmdjLCBjaGFyICoqYXJndikKewogICBp bnQgZmRbMl07CiAgIGludCBpOwogICBjaGFyIGJ1ZlsyXTsKICAgZmRfc2V0IHdyaXRlX2Zk czsKICAgc3RydWN0IHRpbWV2YWwgdHY7CgogICAvKiBpbml0aWFsaXplICovCiAgIGJ1Zlsw XSA9ICdoJzsKICAgYnVmWzFdID0gJ2knOwoKICAgZG8KICAgewogICAgICAvKiBjcmVhdGUg cGlwZSAqLwogICAgICBpZiAoMCA+IHBpcGUoZmQpKQogICAgICB7CiAgICAgICAgIHByaW50 ZigicGlwZSBlcnJvciAtICVzXG4iLCBzdHJlcnJvcihlcnJubykpOwogICAgICAgICBicmVh azsKICAgICAgfQoKICAgICAgLyoKICAgICAgICogbG9vcCB0d2ljZQogICAgICAgKiBzZWxl Y3QgZm9yIHdyaXRlLCB0aGVuIHdyaXRlIG9uZSBieXRlCiAgICAgICAqIGZpcnN0IHNlbGVj dCBzdWNjZWVkcywgc2Vjb25kIGZhaWxzCiAgICAgICAqLwogICAgICBmb3IgKGkgPSAwOyBp IDwgMjsgaSsrKQogICAgICB7CgogICAgICAgICBwcmludGYoIml0ZXJhdGlvbiAlZFxuIiwg aSArIDEpOwoKICAgICAgICAgLyogZG8gc2VsZWN0ICovCiAgICAgICAgIEZEX1pFUk8oJndy aXRlX2Zkcyk7CiAgICAgICAgIEZEX1NFVChmZFsxXSwgJndyaXRlX2Zkcyk7CiAgICAgICAg IHR2LnR2X3NlYyA9IDA7CiAgICAgICAgIHR2LnR2X3VzZWMgPSAwOwogICAgICAgICBzd2l0 Y2ggKHNlbGVjdChmZFsxXSArIDEsIE5VTEwsICZ3cml0ZV9mZHMsIE5VTEwsICZ0dikpCiAg ICAgICAgIHsKICAgICAgICAgICAgY2FzZSAtMToKICAgICAgICAgICAgICAgLyogc2hvdWxk IHByb2JhYmx5IGNoZWNrIGZvciBFSU5UUiBhbmQvb3IgRVdPVUxEQkxPQ0sgKi8KICAgICAg ICAgICAgICAgcHJpbnRmKCJzZWxlY3QgZXJyb3IgLSAlc1xuIiwgc3RyZXJyb3IoZXJybm8p KTsKICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMDoKICAgICAgICAg ICAgICAgLyogbm8gSS9PICovCiAgICAgICAgICAgICAgIHByaW50Zigic2VsZWN0IHJldHVy bmVkIDAgLS0gcGlwZSBub3Qgd3JpdGFibGVcbiIpOwogICAgICAgICAgICAgICBicmVhazsK ICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICAgLyogbWFrZSBzdXJlIG91ciBm ZCBpcyB3cml0YWJsZSAqLwogICAgICAgICAgICAgICBpZiAoRkRfSVNTRVQoZmRbMV0sICZ3 cml0ZV9mZHMpKQogICAgICAgICAgICAgICAgICBwcmludGYoInNlbGVjdCBzYXlzIHBpcGUg aXMgd3JpdGFibGVcbiIpOwogICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICAg IHByaW50Zigic2VsZWN0IHNheXMgcGlwZSBpcyBub3Qgd3JpdGFibGVcbiIpOwogICAgICAg ICB9CgogICAgICAgICAvKiBkbyB3cml0ZSAqLwogICAgICAgICBzd2l0Y2ggKHdyaXRlKGZk WzFdLCBidWYgKyBpLCAxKSkKICAgICAgICAgewogICAgICAgICAgICBjYXNlIC0xOgogICAg ICAgICAgICAgICAvKiBzaG91bGQgcHJvYmFibHkgY2hlY2sgZm9yIEVJTlRSIGFuZC9vciBF V09VTERCTE9DSyAqLwogICAgICAgICAgICAgICBwcmludGYoIndyaXRlIGVycm9yIC0gJXNc biIsIHN0cmVycm9yKGVycm5vKSk7CiAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAg ICBjYXNlIDA6CiAgICAgICAgICAgICAgIC8qIG5vIEkvTyAqLwogICAgICAgICAgICAgICBw cmludGYoIndyaXRlIHJldHVybmVkIDAgLS0gcGlwZSBjbG9zZWRcbiIpOwogICAgICAgICAg ICAgICBicmVhazsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICAgcHJpbnRm KCJ3cml0ZSBzdWNjZWVkZWRcbiIpOwogICAgICAgICAgICAgICBicmVhazsKICAgICAgICAg fQogICAgICB9CiAgIH0KICAgd2hpbGUgKDApOwoKICAgZXhpdCgwKTsKfQo= --------------8B002184CE22B1389FED5AD8--