fix: Don't close upstream on HttpFile::Flush (#1201)

Closing the upstream on flush will effectively terminate the ongoing
curl connection. This means that we would need re-establish the
connection in order to resume writing, this is not what we want. In the
spirit of the documentation of File::Flush

```c++
/// Flush the file so that recently written data will survive an 
/// application crash (but not necessarily an OS crash). For 
/// instance, in LocalFile the data is flushed into the OS but not 
/// necessarily to disk.
```

We will instead wait for the curl thread to finish consuming what ever
might be in the upload cache, but leave the connection open for
subsequent writes.

Fixes #1196
This commit is contained in:
Peter Zebühr 2023-07-06 04:38:01 +07:00 committed by GitHub
parent d687ad1ed0
commit 53d91cd0f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -243,6 +243,7 @@ int64_t HttpFile::Read(void* buffer, uint64_t length) {
} }
int64_t HttpFile::Write(const void* buffer, uint64_t length) { int64_t HttpFile::Write(const void* buffer, uint64_t length) {
DCHECK(!upload_cache_.closed());
VLOG(2) << "Writing to " << url_ << ", length=" << length; VLOG(2) << "Writing to " << url_ << ", length=" << length;
return upload_cache_.Write(buffer, length); return upload_cache_.Write(buffer, length);
} }
@ -253,7 +254,8 @@ int64_t HttpFile::Size() {
} }
bool HttpFile::Flush() { bool HttpFile::Flush() {
upload_cache_.Close(); // Wait for curl to read any data we may have buffered.
upload_cache_.WaitUntilEmptyOrClosed();
return true; return true;
} }