Page MenuHomePhabricator

Work around broken PHP fwrite() on nonblocking pipes
ClosedPublic

Authored by epriestley on Dec 9 2013, 4:35 PM.
Tags
None
Referenced Files
F15454192: D7748.diff
Sat, Mar 29, 4:53 PM
F15438262: D7748.id17516.diff
Tue, Mar 25, 11:54 PM
F15438166: D7748.id17521.diff
Tue, Mar 25, 11:38 PM
F15436518: D7748.id.diff
Tue, Mar 25, 2:50 PM
F15436107: D7748.id.diff
Tue, Mar 25, 12:00 PM
F15431198: D7748.diff
Mon, Mar 24, 11:05 AM
F15423779: D7748.id17515.diff
Sat, Mar 22, 6:12 PM
F15391426: D7748.id17521.diff
Mar 15 2025, 9:49 AM
Subscribers

Details

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.

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped