Skip to content
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

pty doesn't respect flowing mode like net.Socket/stream.Readable #652

Open
Et7f3 opened this issue Dec 24, 2023 · 0 comments
Open

pty doesn't respect flowing mode like net.Socket/stream.Readable #652

Et7f3 opened this issue Dec 24, 2023 · 0 comments

Comments

@Et7f3
Copy link

Et7f3 commented Dec 24, 2023

Environment details

  • OS: Linux
  • OS version: 5.15.0-82-generic
  • node-pty version: 1.0.0

Issue description

From Stream I expect to see my string displayed because I fall in the edge case.

$ node -e "
const node_pty = require('node-pty');
const pty = node_pty.spawn('bash', [ '-c', 'echo somet${nothing}hing' ]);
pty.pause();
setTimeout(() => { pty._socket.on('data', console.log); pty.on('data', console.log); pty.resume(); console.log('data is lost'); }, 2000);
"
data is lost

I see that PipeSocket inherit from net.Socket and it mention that data is dropped if no listener:

The data will be lost if there is no listener when a Socket emits a 'data' event.

https://nodejs.org/api/net.html#event-data however this seems like it is untouched since "v0.1.90" so most likely wrong. I just opened an upstream issue to confirm.

I tried to debug and here are my findings:
node-pty add a data handler with code that emulate EventEmitter (with EventEmitter2)

this.on('data', e => this._onData.fire(e));

Is their a particular reason to recreate this code path with no value added (it simply forward argument) maybe a POO quircks.

When we strace we see the data is read by node so the data is lost between nodejs runtime and node-pty.

$ strace -f -e /write,read node -e "
const node_pty = require('node-pty');
const pty = node_pty.spawn('bash', [ '-c', 'echo somet${nothing}hing' ]);
pty.pause();
setTimeout(() => { pty._socket.on('data', console.log); pty.on('data', console.log); pty.resume(); console.log('data is lost'); }, 2000);
" 2>&1 | grep something
[pid 785556] write(1, "something\n", 10) = 10
[pid 785546] read(23, "something\r\n", 65536) = 11

(I added ${nothing} to be sure we read the output produce by bash)

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

No branches or pull requests

1 participant