#47540 [Opn]: CLI can go into an infinite write() loop when ignore_user_abort(true)

From: Date: Mon, 02 Mar 2009 09:05:44 +0000
Subject: #47540 [Opn]: CLI can go into an infinite write() loop when ignore_user_abort(true)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-134310@lists.php.net to get a copy of this message
 ID:               47540
 User updated by:  tstarling at wikimedia dot org
 Reported By:      tstarling at wikimedia dot org
 Status:           Open
-Bug Type:         *General Issues
+Bug Type:         CGI related
 Operating System: Linux
 PHP Version:      5.2CVS-2009-03-02 (CVS)
 New Comment:

Fixed category.


Previous Comments:
------------------------------------------------------------------------

[2009-03-02 04:01:46] tstarling at wikimedia dot org

Description:
------------
sapi_cli_ub_write() is faulty and may go into a tight infinite loop
under certain circumstances. If write() produces an error, it calls
php_handle_aborted_connection(), but if ignore_user_abort(true) has been
called, this does not exit the request. Thus it enters an infinite
loop.

Bug #20053 is a similar bug in a different SAPI. It's likely that many
SAPIs have copied this code and suffer the same problem.

Reproduce code:
---------------
<?php
ignore_user_abort(true);
while ( true ) {
	fwrite( STDERR, microtime(true) . "\n" );
	echo "Hello\n";
	usleep(500000);
}
?>

Run it like this:

$ php nfs-test.php > /mnt/some-nfs-mount/test-file

Then while that is running, on another server:

$ rm /mnt/some-nfs-mount/test-file



Expected result:
----------------
It should exit when the file is removed, like it does when
ignore_user_abort(true) is not called.

Actual result:
--------------
After a few seconds, the stderr output will stop ticking, and strace
will show a flood of:

write(1, "Hello\n", 6)                  = -1 ESTALE (Stale NFS file
handle)
write(1, "Hello\n", 6)                  = -1 ESTALE (Stale NFS file
handle)
write(1, "Hello\n", 6)                  = -1 ESTALE (Stale NFS file
handle)
write(1, "Hello\n", 6)                  = -1 ESTALE (Stale NFS file
handle)
write(1, "Hello\n", 6)                  = -1 ESTALE (Stale NFS file
handle)
write(1, "Hello\n", 6)                  = -1 ESTALE (Stale NFS file
handle)



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=47540&edit=1



Thread (4 messages)

« previous php.bugs (#134310) next »