| 458 | // no upstream status exists, so 502 Bad Gateway is the right answer |
| 459 | // here — and it's also the one DuckDB's httpfs treats as transient. |
| 460 | slog.Error("Failed to fetch.", "url", r.URL.String(), "range", rangeHeader, "error", err) |
| 461 | http.Error(w, err.Error(), http.StatusBadGateway) |
| 462 | return |
| 463 | } |
| 464 | |
| 465 | // fetchDedup already committed the body to disk under cacheKey. Serve it by |
| 466 | // streaming from the file (openFile, not Open — the miss was already counted, |
| 467 | // so this must not also register a hit). |
| 468 | reader, size, ok := p.store.openFile(cacheKey) |
| 469 | if !ok { |
| 470 | // The entry was evicted in the narrow window between commit and serve. |
| 471 | // 502 so httpfs retries rather than receiving a truncated body. |