Repository: microsoft/node-pty

Issue #72: data events can be fired after exit is fired
Created: 2017-04-03T18:55:08Z
Downstream issue/repro: microsoft/vscode#23051
Temporary fix: microsoft/vscode@9464b54
Relevant commit that tried to fix the problem: chjj/pty.js@4af6285

Duplicate issue #674: `.onData()` doesn't give all data
Created: 2024-03-15T09:19:56Z
Environment details

OS: NixOS 23.11.5328.51063ed4f234 (Tapir) x86_64
Kernel: 6.1.81
node-pty version: 1.0.0 and 1.1.0-beta12

Issue description
.onData() appears to not give the last batch of output from the process. I've only been able to recreate the issue on NixOS.
Below is an example of trying to run ls -l /etc but as you can see the output is cut off half way through the line. I've tried commands other ls and I get similar results. I've tried both the latest and beta versions of node-pty and I get the same behaviour. I've also tried multiple Node.js versions, 18, 20, 21 and I get the same result. Re-running the node -e 'require(... command often cuts off the output in different places.
/tmp/tmp.ivJDE6RJN4 is 📦 v1.0.0 via  v20.11.1 
❯ node -e 'require("node-pty").spawn("ls", [ "-l" , "/etc" ], {}).onData(console.log)'
total 180

-rw-r--r-- 1 root root     44 Mar 14 15:34 adjtime
drwxr-xr-x 3 root root   4096 Feb  6 14:10 alsa
drwxr-xr-x 3 root root   4096 Feb 12 16:04 avahi
lrwxrwxrwx 1 root root     18 Mar 14 15:36 bashrc -> /etc/static/bashrc
drwxr-xr-x 2 root root   4096 Mar 14 15:36 binfmt.d
lrwxrwxrwx 1 root root     16 Mar 14 15:36 cups -> /etc/static/cups
lrwxrwxrwx 1 root root     18 Mar 14 15:36 dbus-1 -> /etc/static/dbus-1
drwxr-xr-x 2 root root   4096 Mar 14 15:36 default
drwxr-xr-x 3 root root   4096 Mar 14 15:36 direnv
drwxr-xr-x 2 root root   4096 Mar 14 15:36 egl
lrwxrwxrwx 1 root root     17 Mar 14 15:36 fonts -> /etc/static/fonts
lrwxrwxrwx 1 root root     17 Mar 14 15:36 fstab -> /etc/static/fstab
lrwxrwxrwx 1 root root     21 Mar 14 15:36 fuse.conf -> /etc/static/fuse.conf
lrwxrwxrwx 1 root root     21 Mar 14 15:36 gitconfig -> /etc/static/gitconfig
drwxr-xr-x 2 root root   4096 Feb  8 13:52 gnupg
-rw-r--r-- 1 root root    925 Mar 14 15:36 group
lrwxrwxrwx 1 root root     21 Mar 14 15:36 host.conf -> /etc/static/host.conf
lrwxrwxrwx 1 root root     20 Mar 14 15:36 hostname -> /etc/static/hostname
lrwxrwxrwx 1 root root     17 Mar 14 15:36 hosts -> /etc/static/hosts
lrwxrwxrwx 1 root root     19 Mar 14 15:36 inputrc -> /etc/static/inputrc
drwx------ 2 root root   4096 Feb  6 14:10 ipsec.d
lrwxrwxrwx 1 root root     17 Mar 14 15:36 issue -> /etc/static/issue
lrwxrwxrwx 1 root root     15 Mar 14 15:36 kbd -> /etc/static/kbd
drwxr-xr-x 3 root root   4096 Feb  6 14:10 libblockdev
lrwxrwxrwx 1 root root     23 Mar 14 15:36 locale.conf -> /etc/static/locale.conf
lrwxrwxrwx 1 root root     27 Mar 14 15:36 localtime -> /etc/zoneinfo/Europe/London
lrwxrwxrwx 1 root root     22 Mar 14 15:36 login.defs -> /etc/static/login.defs
lrwxrwxrwx 1 root root     23 Mar 14 15:36 lsb-release -> /etc/static/lsb-release
drwxr-xr-x 2 root root   4096 Mar 14 15:36 lvm
-r--r--r-- 1 root root     33 Feb  6 14:10 machine-id
lrwxrwxrwx 1 root root     23 Mar 14 15:36 man_db.conf -> /etc/static/man_db.conf
drwxr-xr-x 2 root root   4096 Mar 14 15:36 modprobe.d
drwxr-xr-x 2 root root   4096 Mar 14 15:36 modules-load.d
lrwxrwxrwx 1 root root     14 Mar 14 15:36 mtab -> ../proc/mounts
lrwxrwxrwx 1 root root     18 Mar 14 15:36 nanorc -> /etc/static/nanorc
lrwxrwxrwx 1 root root     20 Mar 14 15:36 netgroup -> /etc/static/netgroup
drwxr-xr-x 4 root root   4096 Mar 14 15:36 NetworkManager
drwxr-xr-x 2 root root   4096 Mar 14 15:36 nix
drwxr-xr-x 2 root root   4096 Feb  6 14:01 nixos
-rw-r--r-- 1 root root      0 Feb  6 14:10 NIXOS
lrwxrwxrwx 1 root root     21 Mar 14 15:36 nscd.conf -> /etc/static/nscd.conf
lrwxrwxrwx 1 root root     25 Mar 14 15:36 nsswitch.conf -> /etc/static/nsswitch.conf
drwxr-xr-x 2 root root   4096 Mar 14 15:36 nvidia
lrwxrwxrwx 1 root root     22 Mar 14 15:36 os-release -> /etc/static/os-release
drwxr-xr-x 2 root root   4096 Mar 14 15:36 pam
drwxr-xr-x 2 root root   4096 Mar 14 15:36 pam.d
-rw-r--r-- 1 root root   4357 Mar 14 15:36 passwd
-rw-r--r-- 1 root root   4086 Feb  6 14:10 passwd-
drwxr-xr-x 3 root root   4096 Feb  6 14:10 pki
drwxr-xr-x 3 root root   4096 Feb  6 14:10 polkit-1
-rw-r--r-- 1 root root    239 Feb 12 16:54 printcap
lrwxrwxrwx 1 root root     19 Mar 14 15:36 profile -> /etc/static/profile
drwxr-xr-x 3 root root   4096 Feb  6 14:10 profiles
lrwxrwxrwx 1 root root     21 Mar 14 15:36 protocols -> /etc/static/protocols
drwxr-xr-x 2 root root   4096 Mar 14 15:36 pulse
-rw-r--r-- 1 root root    117 Mar 14 15:36 resolv.conf
-rw-r--r-- 1 root root      0 Feb  6 13:17 resolv.conf.bak
lrwxrwxrwx 1 root root     27 Mar 14 15:36 resolvconf.conf -> /etc/static/resolvconf.conf
lrwxrwxrwx 1 root root     15 Mar 14 15:36 rpc -> /etc/static/rpc
drwxr-xr-x 2 root root   4096 Mar 14 15:36 samba
lrwxrwxrwx 1 root root     21 Mar 14 15:36 sddm.conf -> /etc/static/sddm.conf
lrwxrwxrwx 1 root root     20 Mar 14 15:36 services -> /etc/static/services
lrwxrwxrwx 1 root root     27 Mar 14 15:36 set-environment -> /etc/static/set-environment
-rw-r----- 1 root shadow 1218 Mar 14 15:

/tmp/tmp.ivJDE6RJN4 is 📦 v1.0.0 via  v20.11.1 
❯

Closing comment (2024-12-17T18:00:18Z): /duplicate #72