only end stream if it is open already