Skip to content
This repository was archived by the owner on Apr 30, 2021. It is now read-only.

Conversation

@kjk
Copy link
Contributor

@kjk kjk commented Aug 2, 2019

It's unlikely to happen, but Close() on a file being written to can fail due to unflushed os buffers. Close might fail even though io.Copy said it wrote all the data to the destination.

Does not apply to files being read from so no need to check error from source.Close()

@yevgenypats
Copy link
Contributor

Interesting. Wasn't aware of that in Go. Can you link to some blog/ data about this?

@kjk
Copy link
Contributor Author

kjk commented Aug 2, 2019

It's not really a Go thing but an operating system thing. On the lowest level, a close syscall might fail which will propagate to file.Close().

https://www.joeshaw.org/dont-defer-close-on-writable-files/
https://www.reddit.com/r/golang/comments/3735so/do_we_have_to_check_for_errors_when_we_call_close/

https://linux.die.net/man/2/close:

Not checking the return value of close() is a common but nevertheless serious programming error.

@yevgenypats
Copy link
Contributor

cool.

@yevgenypats yevgenypats merged commit ca5e96b into fuzzitdev:master Aug 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants