Fix NPE when stream is already closed.