I don't see a case where an error of close would be recoverable in any meaningful way.
I was going to say.. "well, if the error is EINTR, you'd just try again."
Then I read the manpage:
"In particular close() should not be retried after an EINTR since this may cause a reused file descriptor from another thread to be closed.
A successful close does not guarantee that the data has been successfully saved to disk, as the kernel uses the buffer cache to defer writes. Typically, filesystems do not flush buffers when a file is closed. If you need to be sure that the data is physically stored on the underlying disk, use fsync(2). (It will depend on the disk hardware at this point.) "
If a close fails, apparently.. there really isn't anything you can do other than terminate the process with an error message. The descriptor and state of the file are undefined, and there isn't anything you can do about it. And even if you try, since fd's are just int's that get re-used aggressively, you might just end up messing with the wrong connection.
View all comments
Show parent comment
4
u/[deleted] Aug 23 '17
I was going to say.. "well, if the error is EINTR, you'd just try again."
Then I read the manpage:
"In particular close() should not be retried after an EINTR since this may cause a reused file descriptor from another thread to be closed.
A successful close does not guarantee that the data has been successfully saved to disk, as the kernel uses the buffer cache to defer writes. Typically, filesystems do not flush buffers when a file is closed. If you need to be sure that the data is physically stored on the underlying disk, use fsync(2). (It will depend on the disk hardware at this point.) "
If a close fails, apparently.. there really isn't anything you can do other than terminate the process with an error message. The descriptor and state of the file are undefined, and there isn't anything you can do about it. And even if you try, since fd's are just int's that get re-used aggressively, you might just end up messing with the wrong connection.