Stream is already closed, prevent NPE