From 391c46c8f4136e3f906135fb095556af6d6cc9a6 Mon Sep 17 00:00:00 2001 From: Carlo Piovesan Date: Thu, 4 Sep 2025 10:39:24 +0200 Subject: [PATCH] When a HTTPFIleHandle has an Etag, and that changes over time, consider the read unreliable --- extension/httpfs/httpfs.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/extension/httpfs/httpfs.cpp b/extension/httpfs/httpfs.cpp index 6f2f16c..9f8b784 100644 --- a/extension/httpfs/httpfs.cpp +++ b/extension/httpfs/httpfs.cpp @@ -226,6 +226,11 @@ unique_ptr HTTPFileSystem::GetRangeRequest(FileHandle &handle, str } if (static_cast(response.status) < 300) { // done redirecting out_offset = 0; + + if (response.HasHeader("ETag") && !hfh.etag.empty() && response.GetHeaderValue("ETag") != hfh.etag) { + throw HTTPException(response, "ETag was initially %s and now it returned %s, this likely means the remote file has changed.\nTry restart the read / close file-handle and restart (e.g. `DETACH` in case of database file).", hfh.etag, response.GetHeaderValue("ETag")); + } + if (response.HasHeader("Content-Length")) { auto content_length = stoll(response.GetHeaderValue("Content-Length")); if ((idx_t)content_length != buffer_out_len) {