Fixes T13243. This is generally a mess, but this patch seems like it's a step forward and refines our handling of possible conditions here.
I think this can only hurt us if there's some error condition where all of these are true:
- fwrite() returns 0.
- stream_select() errors.
- The stream is legitimately in a dead/error/failures state and should not be retried.
Ideally, this shouldn't exist. But it's hard to be terribly confident that this is actually true.
(I'll hold this until after the release cut.)