properly exit when the client and stdin are done