php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49084 PSFS_FEED_ME causes stream block
Submitted: 2009-07-28 06:07 UTC Modified: 2009-07-31 18:33 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: morrisdavidd at gmail dot com Assigned:
Status: Not a bug Package: Streams related
PHP Version: 5.3.0 OS: Linux/Unix
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: morrisdavidd at gmail dot com
New email:
PHP Version: OS:

 

 [2009-07-28 06:07 UTC] morrisdavidd at gmail dot com
Description:
------------
According to: http://us3.php.net/manual/en/function.stream-filter-register.php

The return value of PSFS_FEED_ME for the method filter of extended classes of php_user_filter means: "Filter processed successfully, however no data was available to return. More data is required from the stream or prior filter."

However, using the return value of PSFS_FEED_ME also inadvertently causes a block on stream read requests that should not be blocked (and an infinite poll for data?).

Reproduce code:
---------------
bug_demo.php:
http://capricorn.physics.fsu.edu/~ddm05/bug_demo.txt

test2.php:
http://capricorn.physics.fsu.edu/~ddm05/test2.txt

Expected result:
----------------
When replacing the phrase "badFilter" with "goodFilter" in line 44:

bool(true)
Loop!
xLoop!
xxtest2: 1248760722
Loop!
xLoop!
xLoop!
xLoop!
xxtest2: 1248760724
Loop!
xLoop!
xLoop!
xLoop!
xxtest2: 1248760726
Loop!
...

Actual result:
--------------
bool(true)
Loop!
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-28 06:08 UTC] morrisdavidd at gmail dot com
Actual result is when leaving "badFilter".)
 [2009-07-29 13:50 UTC] jani@php.net
Can you please provide reproducing scripts that actually give the expected output with the "goodFilter" ?? And fyi, with non-blocking you should use fread() instead of fgets()..
 [2009-07-29 19:00 UTC] morrisdavidd at gmail dot com
See:

http://capricorn.physics.fsu.edu/~ddm05/working_demo.txt

Or were you asking for something else?

The whole fgets vs fread thing shouldn't matter for this bug, I've came across plenty of "you should use fgets instead of fread when not blocking" statements before I submitted this code. So I did test fread which had no changes with respect to the bug except more overhead to extract separate lines.)
 [2009-07-29 23:15 UTC] jani@php.net
We must have different idea of "working" or this is what you expect:

$ sapi/cli/php -n working_demo.txt
bool(true)
Loop!
xLoop!
x

Now, what should this output?
 [2009-07-30 02:42 UTC] morrisdavidd at gmail dot com
Yes, that is what I expect to see.

To restate:
I do not expect to see an infinite number of "x"es on any non-block read like you see in "bug_demo". I expect the non-block read to return immediately resulting in another "Loop!" statement. i.e. I expect the output of "bug_demo" with the "badFilter" to be the same as with the "goodFilter" and the number of "x"es to be similar to the number of "Loop!"s.)
 [2009-07-31 16:57 UTC] jani@php.net
Well, your test is inherently buggy. You never return PSFS_PASS_ON from the filter to begin with. And yes, to get this really working you HAVE to use fread(). 
 [2009-07-31 18:33 UTC] morrisdavidd at gmail dot com
My code was not intended to be "real world", it was intended to accent a bug. However, here's a slightly rewritten bug demonstration:
http://capricorn.physics.fsu.edu/~ddm05/bug_demo2.txt

With non-blocking I/O, I expect to see ~4 "Loop!" statements for each timestamp, since "Loop!" echos every .5 sec and the timestamp echos every 2 seconds.

P.S. The output should be the same as when the filter is removed.)
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Oct 19 13:01:27 2019 UTC