Skip to content

Commit

Permalink
fix: Don't close upstream on HttpFile::Flush (shaka-project#1201)
Browse files Browse the repository at this point in the history
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 shaka-project#1196
  • Loading branch information
petzeb committed Jul 5, 2023
1 parent d687ad1 commit 53d91cd
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packager/file/http_file.cc
Expand Up @@ -243,6 +243,7 @@ int64_t HttpFile::Read(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;
return upload_cache_.Write(buffer, length);
}
Expand All @@ -253,7 +254,8 @@ int64_t HttpFile::Size() {
}

bool HttpFile::Flush() {
upload_cache_.Close();
// Wait for curl to read any data we may have buffered.
upload_cache_.WaitUntilEmptyOrClosed();
return true;
}

Expand Down

0 comments on commit 53d91cd

Please sign in to comment.