Avoid terminating MultiRangeHttpFetcher twice.
If the delegate (DownloadAction) called TerminateTransfer() in the
ReceivedBytes() callback, and we received all bytes of the current
range, it will try to terminate again.
This only happens if the base fetcher is FileFetcher, but not
LibcurlHttpFetcher because LibcurlHttpFetcher can not terminate in
a write callback, while FileFetcher doesn't have this limit.
Bug: 68141222
Test: scripts/update_device.py dummy-ota-ab-small.dev.ab39d95e.zip --file
Change-Id: Ibe228241055abfa50cb7b916f4216bb0ae3e54ab
diff --git a/common/multi_range_http_fetcher.cc b/common/multi_range_http_fetcher.cc
index 1189fde..dc4b7c1 100644
--- a/common/multi_range_http_fetcher.cc
+++ b/common/multi_range_http_fetcher.cc
@@ -101,6 +101,12 @@
LOG_IF(WARNING, next_size <= 0) << "Asked to write length <= 0";
if (delegate_) {
delegate_->ReceivedBytes(this, bytes, next_size);
+ // If the transfer was already terminated by |delegate_|, return immediately
+ // to avoid calling TerminateTransfer() again.
+ if (!base_fetcher_active_) {
+ LOG(INFO) << "Delegate has terminated the transfer.";
+ return;
+ }
}
bytes_received_this_range_ += length;
if (range.HasLength() && bytes_received_this_range_ >= range.length()) {