Basically it seems like if the user tty is closed, we will have to close the pty leader and then manually send SIGHUP to the foreground process group. See also sudo-project/sudo@41978a5, sudo-project/sudo@a2d01a9, sudo-project/sudo@62e4d29, sudo-project/sudo@fb208d3