Fix for crit bug when closing pipe stream