Skip to content

check return value of stream_select including a test case #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 3, 2016

Conversation

cebe
Copy link
Contributor

@cebe cebe commented Feb 27, 2016

This PR contains a test case for #20 as requested by @clue and @WyriHaximus. I have also applied the fix by @mkrauser to make the tests pass.
This fixes the issue described in reactphp/reactphp#296.

The test sets up an event loop and then forks a child process which will send a signal to the current process while it is waiting for stream_select(). This triggers stream_select() to return false and throw a warning.

The test currently uses error_reporting to suppress this warning as in the issue discussion the supression of the warning with @ was no wanted. I think there should be a benchmark to check if adding an @ to stream select has any negative effect. I doubt it.

@cebe
Copy link
Contributor Author

cebe commented Feb 27, 2016

Additional note about adding @ to stream_select(): The "performance overhead" of suppressing the warning will hardly have any effect as stream_select() is supposed to be waiting some amount of time anyway in most cases. In the cases where it returns immediately, the reading and writing of streams will have much bigger impact than the very small amount of time added by @ operator.

@jmalloc
Copy link
Contributor

jmalloc commented Mar 1, 2016

Just in case the discussion around @ is what holds this up, I'd like to add this totally non-authoratative piece of information on the subject: https://github.com/ezzatron/fig-standards/blob/error-handler/proposed/error-handler-meta.md#431-performance-considerations

From my memory of the PHP source, @ simply temporarily set the error reporting level. Problems only arose when suppression of an error allowed failing code to continue execution of a loop with error logging enabled, i.e. with added I/O.

I guess the take-away from that would be to ensure you're not logging errors that indicate signal interrupts, as I can only assume that would be a blocking I/O operation.

- error suppression does not hurt much if handled correctly
  https://github.com/ezzatron/fig-standards/blob/error-handler/proposed/error-handler-meta.md#431-performance-considerations
- it make this library work without having to suppress warnings for all the code!
- StreamSelect loop is not the loop of choice if you really care about performance anyway.
- The "performance overhead" of suppressing the warning will hardly have any effect as stream_select() is supposed to be waiting some amount of time anyway in most cases.
  In the cases where it returns immediately, the reading and writing of streams will have much bigger impact than the very small amount of time added by @ operator.
@cebe
Copy link
Contributor Author

cebe commented Mar 1, 2016

added a commit for error suppression 5916176 commit message includes detailed resoning about why it should be added.

@cebe
Copy link
Contributor Author

cebe commented Mar 1, 2016

the test failure on travis is not caused by the changes btw.

@clue
Copy link
Member

clue commented Mar 1, 2016

Changes LGTM :shipit: Thanks for digging into this @cebe!

@clue
Copy link
Member

clue commented Mar 1, 2016

FWIW: This is currently only tested for the StreamSelectLoop, does it make sense to test / document signal behavior for the other loops?

@cebe
Copy link
Contributor Author

cebe commented Mar 1, 2016

It would make sense of course but I'd do another PR after this one is merged. The scope of this PR is fixing an issue that only exists in stream select loop.

@cebe
Copy link
Contributor Author

cebe commented Mar 3, 2016

@clue @WyriHaximus can we get this one merged please, so I can start checking signal support for other event loops?

@cboden
Copy link
Member

cboden commented Mar 3, 2016

On one system I'm getting:

Fatal error: Call to undefined function React\Tests\EventLoop\pcntl_signal() in /Users/cboden/Repositories/React/event-loop/tests/StreamSelectLoopTest.php on line 107

Which can be fixed by checking extension_loaded('pcntl') in StreamSelectLoopTest.php and skipping the test if false.

The other issue I'm seeing is on HHVM 3.6.6:

  1. React\Tests\EventLoop\StreamSelectLoopTest::testSignalInterruptWithStream with data set #0 ('SIGUSR1', 10)
    stream_select(): unable to select [4]: Interrupted system call (max_fd=4)

  2. React\Tests\EventLoop\StreamSelectLoopTest::testSignalInterruptWithStream with data set Set autoload to false #2 ('SIGTERM', 15)
    stream_select(): unable to select [4]: Interrupted system call (max_fd=7)

@cboden cboden added this to the v0.4.2 milestone Mar 3, 2016
@cboden
Copy link
Member

cboden commented Mar 3, 2016

I goofed a little bit...phpunit on my HHVM machine was running PHP5 with Debug's scream option turned on (errors not suppressed). Here is the actual error HHVM is giving me:

  1. React\Tests\EventLoop\StreamSelectLoopTest::testSignalInterruptNoStream with data set #0 ('SIGUSR1', 10)
    Failed asserting that false is true.

@cebe
Copy link
Contributor Author

cebe commented Mar 3, 2016

Which can be fixed by checking extension_loaded('pcntl') in StreamSelectLoopTest.php and skipping the test if false.

done, ef2ced8

Need to install HHVM on my machine to test this.

@cebe
Copy link
Contributor Author

cebe commented Mar 3, 2016

hm... HHVM fails only on SIGUSR1 but not on the other signals...

@cebe
Copy link
Contributor Author

cebe commented Mar 3, 2016

Found it, the forked process needs some startup time on HHVM. Added another timer to capture the late signal.

@cboden cboden merged commit dcbd909 into reactphp:master Mar 3, 2016
@cboden
Copy link
Member

cboden commented Mar 3, 2016

Awesome! Thanks for your diligent work @cebe!

@cebe cebe deleted the test-signals branch March 3, 2016 23:53
@cebe
Copy link
Contributor Author

cebe commented Mar 3, 2016

You're welcome, thanks for merging :)

@WyriHaximus
Copy link
Member

Thanks for the work @cebe 👍

@mkrauser
Copy link
Contributor

mkrauser commented Mar 4, 2016

@cebe Yes, very nice work with the test!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants