Fixed I/O error after closing a port