Subject: bug#56025: 29.0.50; em-extpipe-test-2 times out on EMBA and Cygwin

From: Jim Porter <[email-masked]>
Date: Wed, 6 Jul 2022 21:35:36 -0700

On 7/6/2022 3:33 PM, Ken Brown wrote:
> On 6/30/2022 11:52 PM, Jim Porter wrote:
>> Ok, I've got Cygwin set up (though I'm just using the prebuilt Cygwin 
>> Emacs for now). I can confirm that the following hangs until I send 
>> another EOF via `C-c C-d':
>>
>>    echo hi | rev
> 
> Yes, but that's because of the behavior of certain platforms (e.g., 
> Cygwin and Solaris) with respect to EOF, as I said in an earlier 
> message.

Yeah, I think that's fine, and the change to send an extra EOF for 
compatibility with (non-master) Cygwin and Solaris makes sense to me. I 
just wanted to be sure to mention that I could see the issue too so that 
I can (hopefully) verify that it's fixed if/when we come up with a 
more-reliable fix.

>> However, if I evaluate the following first, the above command works 
>> just fine:
>>
>>    (add-to-list 'eshell-needs-pipe "rev")
>>
>> Normally, Eshell starts each process using ptys to control them. 
>> However, the above Elisp code tells Eshell to use a pipe for "rev"[1].
> 
> That makes sense.  You're no longer relying on Eshell sending EOF to 
> rev, but rather you're letting rev discover EOF because no process holds 
> the pipe open for writing, forcing any pending read to stop blocking.

Maybe it would be good to do it this way in general though, since this 
would let us completely avoid the behavioral differences of EOF on 
various platforms. I believe using a pipe should work consistently 
everywhere, right? (It would also probably fix some other issues with 
Eshell pipelines, but I'll need to read up on ptys, since it's been a 
long time since I've done anything with them.)

>> However, I don't think this fully answers things, since I also see 
>> inconsistent results if I run "echo hi | rev" a bunch of times. 
>> Sometimes it prints "ih" and then I need to hit `C-c C-d` once to stop 
>> it. Other times it doesn't print anything and I need to hit `C-c C-d' 
>> twice.
> 
> Interesting.  I've never seen that.  It's as though "rev" just didn't 
> get one of the EOFs.

Yeah, that's what it seems like to me too. I'm not able to reproduce 
this on GNU/Linux (at least not yet; I'll try some more things out). 
I'll keep poking at the Cygwin version too, and start experimenting with 
Emacs's src/process.c to try and allow using a pty for only stdin *or* 
stdout (instead of both). I think that would make Eshell's pipelines 
behaves more like other shells, which would squash a lot of bugs in this 
area.