diff --git a/src/libostree/ostree-fetcher-curl.c b/src/libostree/ostree-fetcher-curl.c index 7b6ee77f93..93f93c323a 100644 --- a/src/libostree/ostree-fetcher-curl.c +++ b/src/libostree/ostree-fetcher-curl.c @@ -578,6 +578,8 @@ request_unref (FetcherRequest *req) g_ptr_array_unref (req->mirrorlist); g_free (req->filename); g_clear_error (&req->caught_write_error); + if (req->out_tmpfile_fd != -1) + (void) close (req->out_tmpfile_fd); g_free (req->out_tmpfile); if (req->output_buf) g_string_free (req->output_buf, TRUE); @@ -782,17 +784,12 @@ _ostree_fetcher_request_async (OstreeFetcher *self, req->max_size = max_size; req->flags = flags; req->is_membuf = is_membuf; + /* We'll allocate the tmpfile on demand, so we handle + * file I/O errors just in the write func. + */ + req->out_tmpfile_fd = -1; if (req->is_membuf) - { - req->output_buf = g_string_new (""); - } - else - { - /* We'll allocate the tmpfile on demand, so we handle - * file I/O errors just in the write func. - */ - req->out_tmpfile_fd = -1; - } + req->output_buf = g_string_new (""); task = g_task_new (self, cancellable, callback, user_data); /* We'll use the GTask priority for our own priority queue. */ @@ -803,6 +800,12 @@ _ostree_fetcher_request_async (OstreeFetcher *self, initiate_next_curl_request (req, task); g_hash_table_add (self->outstanding_requests, g_steal_pointer (&task)); + + /* Sanity check, I added * 2 just so we don't abort if something odd happens, + * but we do want to abort if we're asked to do obviously too many requests. + */ + g_assert_cmpint (g_hash_table_size (self->outstanding_requests), <, + _OSTREE_MAX_OUTSTANDING_FETCHER_REQUESTS * 2); } void diff --git a/src/libostree/ostree-repo-private.h b/src/libostree/ostree-repo-private.h index a4e59e44bc..e3982b58b0 100644 --- a/src/libostree/ostree-repo-private.h +++ b/src/libostree/ostree-repo-private.h @@ -32,6 +32,9 @@ G_BEGIN_DECLS #define _OSTREE_SUMMARY_CACHE_DIR "summaries" #define _OSTREE_CACHE_DIR "cache" +#define _OSTREE_MAX_OUTSTANDING_FETCHER_REQUESTS 8 +#define _OSTREE_MAX_OUTSTANDING_DELTAPART_REQUESTS 2 + typedef enum { OSTREE_REPO_TEST_ERROR_PRE_COMMIT = (1 << 0) } OstreeRepoTestErrorFlags; diff --git a/src/libostree/ostree-repo-pull.c b/src/libostree/ostree-repo-pull.c index 78c37758a8..6029177786 100644 --- a/src/libostree/ostree-repo-pull.c +++ b/src/libostree/ostree-repo-pull.c @@ -37,9 +37,6 @@ #include -#define MAX_OUTSTANDING_REQUESTS 8 -#define MAX_OUTSTANDING_DELTAPART_REQUESTS 2 - #define OSTREE_REPO_PULL_CONTENT_PRIORITY (OSTREE_FETCHER_DEFAULT_PRIORITY) #define OSTREE_REPO_PULL_METADATA_PRIORITY (OSTREE_REPO_PULL_CONTENT_PRIORITY - 100) @@ -355,7 +352,7 @@ fetcher_queue_is_full (OtPullData *pull_data) { return (pull_data->n_outstanding_metadata_fetches + pull_data->n_outstanding_content_fetches + - pull_data->n_outstanding_deltapart_fetches) == MAX_OUTSTANDING_REQUESTS || + pull_data->n_outstanding_deltapart_fetches) == _OSTREE_MAX_OUTSTANDING_FETCHER_REQUESTS || pull_data->n_outstanding_deltapart_fetches > 1; } @@ -1627,7 +1624,7 @@ start_fetch_deltapart (OtPullData *pull_data, { g_autofree char *deltapart_path = _ostree_get_relative_static_delta_part_path (fetch->from_revision, fetch->to_revision, fetch->i); pull_data->n_outstanding_deltapart_fetches++; - g_assert_cmpint (pull_data->n_outstanding_deltapart_fetches, <=, MAX_OUTSTANDING_DELTAPART_REQUESTS); + g_assert_cmpint (pull_data->n_outstanding_deltapart_fetches, <=, _OSTREE_MAX_OUTSTANDING_DELTAPART_REQUESTS); _ostree_fetcher_request_to_tmpfile (pull_data->fetcher, pull_data->content_mirrorlist, deltapart_path, fetch->size,