Adds input/output closing defensiveness in case already closed.