fix close error handling