From 93d8d57774844cb11888dbd105a2ef60e857d0bb Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Tue, 8 Sep 2026 17:09:40 +0100 Subject: [PATCH] fix: Close body correctly in simple cache --- runtime/fastly/builtins/cache-simple.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/runtime/fastly/builtins/cache-simple.cpp b/runtime/fastly/builtins/cache-simple.cpp index 7fc5d2de33..449ee2ea8a 100644 --- a/runtime/fastly/builtins/cache-simple.cpp +++ b/runtime/fastly/builtins/cache-simple.cpp @@ -337,9 +337,12 @@ bool get_or_set_then_handler(JSContext *cx, JS::HandleObject lookup_state, JS::H auto inserted_res = handle.transaction_insert_and_stream_back(options); if (auto *err = inserted_res.to_err()) { + HANDLE_ERROR(cx, *err); return false; } + transaction.commit(); + auto [body, inserted_handle] = inserted_res.unwrap(); if (!body.valid()) { return false; @@ -348,19 +351,23 @@ bool get_or_set_then_handler(JSContext *cx, JS::HandleObject lookup_state, JS::H if (source_body.valid()) { auto res = body.append(source_body); if (auto *error = res.to_err()) { + HANDLE_ERROR(cx, *err); return false; } } else { auto write_res = body.write_all_back(reinterpret_cast(buf.get()), options.length); if (auto *error = write_res.to_err()) { - return false; - } - auto close_res = body.close(); - if (auto *error = close_res.to_err()) { + HANDLE_ERROR(cx, *err); return false; } } + auto close_res = body.close(); + if (auto *error = close_res.to_err()) { + HANDLE_ERROR(cx, *err); + return false; + } + auto res = inserted_handle.get_body(host_api::CacheGetBodyOptions{}); if (auto *err = res.to_err()) { HANDLE_ERROR(cx, *err); @@ -372,8 +379,6 @@ bool get_or_set_then_handler(JSContext *cx, JS::HandleObject lookup_state, JS::H return false; } - transaction.commit(); - JS::RootedValue result(cx); result.setObject(*entry); JS::ResolvePromise(cx, promise, result);