Verify second-block SQL failure and propagate local download errors

This commit is contained in:
evgeny committed 2026-10-22 18:31:12 +02:00
1 parent a5ef200c52
commit 30887bd72e
2 files changed
+23 -8

No files matched your search

+8 -3
View File
@@ -230,8 +230,8 @@ static int md_dl_pump(struct media_download* dl) {
if (dl->err) return -1;
for (int bi = 0; bi < dl->num_blocks; bi++) {
struct media_download_block* b = &dl->blocks[bi];
if ((b->state == MD_BLK_IDLE || b->state == MD_BLK_WAIT)
&& md_dl_request_block(dl, bi) < 0 && md_dl_failover_block(dl, bi, get_time_tb()) < 0) return -1;
if (b->state != MD_BLK_IDLE && b->state != MD_BLK_WAIT) continue;
if (md_dl_request_block(dl, bi) < 0 && (dl->err || md_dl_failover_block(dl, bi, get_time_tb()) < 0)) return -1;
}
return 0;
}
@@ -243,10 +243,15 @@ int md_dl_failover_block(struct media_download* dl, int bi, uint64_t now_tb) {
if (md_dl_block_inflight(b) && dl->inflight > 0) dl->inflight--;
b->state = MD_BLK_IDLE; b->bytes_received = 0; b->last_progress_tb = now_tb; b->retry_at_tb = 0;
do {
if (dl->err) return -1;
b->attempts++;
DEBUG_WARN(DEBUG_CATEGORY_MEDIA, "%s: failover block=%d attempts=%d/%d holder=%d/%d",
MDL_ID, bi, b->attempts, md_dl_max_attempts(dl->inst), b->holder_idx, b->num_holders);
if (b->attempts >= md_dl_max_attempts(dl->inst)) { b->state = MD_BLK_FAILED; return -1; }
if (b->attempts >= md_dl_max_attempts(dl->inst)) {
b->state = MD_BLK_FAILED;
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "%s: block attempts exhausted block=%d attempts=%d", MDL_ID, bi, b->attempts);
return -1;
}
if (++b->holder_idx >= b->num_holders) {
b->num_holders = 0; b->holder_idx = -1; b->state = MD_BLK_WAIT; b->wait_reason = MD_WAIT_SEARCH;
return 0;