From 07cba4c0c63471ed1219a3bba1978926b827dbb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Zeb=C3=BChr?= Date: Wed, 21 Feb 2024 13:49:27 +0700 Subject: [PATCH] fix: http_file: Close upload cache on task exit In some cases it can happen that the http server responds with a non-successful status code without reading the response body. In this case curl may decide not to read from the cache since there is really no point in sending data to the server. In case some other thread of shaka has already called HttpFile::Flush it may end up deadlocked there waiting for the cache to either close or become empty. Thus, we close the cache when leaving the main thread as no data will be read by curl after it has finished anyways. --- packager/file/http_file.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packager/file/http_file.cc b/packager/file/http_file.cc index e2a27e2d0dd..b50fef6f072 100644 --- a/packager/file/http_file.cc +++ b/packager/file/http_file.cc @@ -372,6 +372,12 @@ void HttpFile::ThreadMain() { error_message); } + // In some cases it is possible that the server has already closed the + // connection without reading the request body. This can for example happen + // when the server responds with a non-successful status code. In this case we + // need to make sure to close the upload cache here, otherwise some other + // thread may block forever on Flush(). + upload_cache_.Close(); download_cache_.Close(); task_exit_event_.Notify(); }