func serveContent was used by docker distribution project,I get 'unexpect eof error 'when I pull image for registry server may be related the bad network(just 20mb bandwidth).I can'not find any error in registry server log,it alwayls return response complete and 200 http status code.so i found error in io.CopyN after debug,it just copy only part of entire content due to ceph( the regitry storage backend ) rst the connection(mayby slow network).
I found same issue in 9709 ,however ,If it's not worth the cost of adding return error,can add error in ResponseWriter.like this
@zhxqgithub, we can't call http.Error as in your proposed change because we've already sent headers at this point (if we've copied at least 1 byte already). That is, CopyN doesn't slurp it all up into memory first. It streams it out. If there's a copy failure, it could be because either the read failed or the write failed. If the write failed, 99 times out of 100 (or more) it's because the client went away, and then a log statement isn't too interesting. A read error might be more interesting to log, I guess. I suppose we could write that to https://golang.org/pkg/net/http/#Server.ErrorLog
changed the title
io.CopyN(w, sendContent, sendSize) why swallow the error??May 9, 2019