From 083ba385d70a6fbc0c89ffbc42f66d035a856139 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Mon, 24 Feb 2020 09:47:52 +0000 Subject: fetch: Automatically handle fetches which fail to finish Signed-off-by: Daniel Silverstone --- content/fetch.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'content/fetch.c') diff --git a/content/fetch.c b/content/fetch.c index 2ac86a812..94654fc6b 100644 --- a/content/fetch.c +++ b/content/fetch.c @@ -98,6 +98,7 @@ struct fetch { int fetcherd; /**< Fetcher descriptor for this fetch */ void *fetcher_handle; /**< The handle for the fetcher. */ bool fetch_is_active; /**< This fetch is active. */ + fetch_msg_type last_msg;/**< The last message sent for this fetch */ struct fetch *r_prev; /**< Previous active fetch in ::fetch_ring. */ struct fetch *r_next; /**< Next active fetch in ::fetch_ring. */ }; @@ -593,6 +594,20 @@ void fetch_abort(struct fetch *f) /* exported interface documented in content/fetch.h */ void fetch_free(struct fetch *f) { + if (f->last_msg < FETCH_MIN_FINISHED_MSG) { + /* We didn't finish, so tell our user that an error occurred */ + fetch_msg msg; + + msg.type = FETCH_ERROR; + msg.data.error = "FetchFailedToFinish"; + + NSLOG(fetch, CRITICAL, + "During the fetch of %s, the fetcher did not finish.", + nsurl_access(f->url)); + + fetch_send_callback(&msg, f); + } + NSLOG(fetch, DEBUG, "Freeing fetch %p, fetcher %p", f, @@ -788,6 +803,7 @@ fetch_multipart_data_new_kv(struct fetch_multipart_data **list, void fetch_send_callback(const fetch_msg *msg, struct fetch *fetch) { + fetch->last_msg = msg->type; fetch->callback(msg, fetch->p); } -- cgit v1.2.3