fix Error[9]: Bad file descriptor