Merge pull request #30257 from ligangbin117/wip-ligangbin-rgw-data-error

rgw:[bug] fix data consistency error casued by rgw sent timeout

Reviewed-by: Yuli Yang <yuliyang@cmss.chinamobile.com>
Reviewed-by: Casey Bodley <cbodley@redhat.com>
This commit is contained in:
Casey Bodley 2020-01-09 13:48:59 -05:00 committed by GitHub
commit 4a23fc109e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,15 +15,17 @@
size_t RGWCivetWeb::write_data(const char *buf, const size_t len)
{
size_t off = 0;
auto to_sent = len;
while (to_sent) {
const int ret = mg_write(conn, buf, len);
const int ret = mg_write(conn, buf + off, to_sent);
if (ret < 0 || ! ret) {
/* According to the documentation of mg_write() it always returns -1 on
* error. The details aren't available, so we will just throw EIO. Same
* goes to 0 that is associated with writing to a closed connection. */
throw rgw::io::Exception(EIO, std::system_category());
} else {
off += static_cast<size_t>(ret);
to_sent -= static_cast<size_t>(ret);
}
}