Homec4science

Work around broken PHP fwrite() on nonblocking pipes

Authored by epriestley <git@epriestley.com> on Dec 9 2013, 22:22.

Description

Work around broken PHP fwrite() on nonblocking pipes

Summary:
Fixes T4219. See comments. PHP returns 0 when writing to nonblocking pipes for both "everything is OK, but this pipe is blocked, so you should wait a little bit and try again" and "nothing is OK, this pipe is broken forever".

This was causing an busy loop in ssh-exec, where it would check if stderr was writable, see it was, try to write to it, get a 0-length write, interpret that as "wait a bit", wait for it to become writable (i.e., immediately!), try to write again, etc.

This was the best workaround I could come up with. I think it should be pretty safe; I'm not aware of any temporary condition or event which can make a pipe unwritable after a select says it's writable other than a write.

Test Plan: Ran git pull a bunch of times and ^C'd it partway through. Previously I could leave a busy process eating a CPU on the server about 50% of the time, depending how good my timing was. I can no longer generate these processes.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4219

Differential Revision: https://secure.phabricator.com/D7748

Details

Committed
epriestley <git@epriestley.com>Dec 9 2013, 22:22
Pushed
aubortMar 17 2017, 12:03
Parents
rPHU900e44191d52: Speed up text markup for test results
Branches
Unknown
Tags
Unknown

Event Timeline

epriestley <git@epriestley.com> committed rPHU69490c53c9c2: Work around broken PHP fwrite() on nonblocking pipes (authored by epriestley <git@epriestley.com>).Dec 9 2013, 22:22