On SIGCHLD do waitpid(-1). use the package 'waitpid'.
Not sure if there is a better way to handle this but this works.
Related PR on pty.js : https://github.com/chjj/pty.js/pull/37