On Wednesday, March 20, 2019 at 10:53:44 PM UTC+1, Kurtis Rader wrote: > > On Wed, Mar 20, 2019 at 2:08 PM Manlio Perillo <manlio....@gmail.com > <javascript:>> wrote: > >> Note from the Linux close documentation: >> >> Not checking the return value of close() is a common but nevertheless >> serious programming error. It is quite possible that errors on a previous >> write <https://linux.die.net/man/2/write>(2) operation are first >> reported at the final close(). Not checking the return value when closing >> the file may lead to silent loss of data. This can especially be observed >> with NFS and with disk quota. >> >> A successful close does not guarantee that the data has been successfully >> saved to disk, as the kernel defers writes. It is not common for a file >> system to flush the buffers when the stream is closed. If you need to be >> sure that the data is physically stored use fsync >> <https://linux.die.net/man/2/fsync>(2). (It will depend on the disk >> hardware at this point.) >> > > There are only two reasons to check if close() has failed: > > 1) Checking if errno == EBADF if that indicates a logic error in the > program because the fd should have been valid at the time of the close(). > > 2) To log a message about an unexpected close() failure. > > And I suggest to use something like:
defer fun() { if err := xxx.Close(); err != nil { log.Printf("here: close(): %v", err) }() But thinking you can do anything about the other failure modes, especially > EINTR, is mistaken. See > > https://lwn.net/Articles/576478/ > http://austingroupbugs.net/view.php?id=529 > https://sourceware.org/bugzilla/show_bug.cgi?id=14627 > > On UNIX systems, Go Close() don't check for EINTR. HPUX is not currently supported by Go, but what about other systems? Manlio Perillo -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.