fix bug in readall(TTY), and modify a repl test to sometimes trigger this potential race condition