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 ++++++++++++++++ content/fetch.h | 10 +++++++++- resources/FatMessages | 3 +++ 3 files changed, 28 insertions(+), 1 deletion(-) 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); } diff --git a/content/fetch.h b/content/fetch.h index 9e80b2685..817d5e2f8 100644 --- a/content/fetch.h +++ b/content/fetch.h @@ -39,19 +39,27 @@ struct ssl_cert_info; */ typedef enum { FETCH_PROGRESS, + FETCH_CERTS, FETCH_HEADER, FETCH_DATA, + /* Anything after here is a completed fetch of some kind. */ FETCH_FINISHED, FETCH_TIMEDOUT, FETCH_ERROR, FETCH_REDIRECT, FETCH_NOTMODIFIED, - FETCH_CERTS, FETCH_AUTH, FETCH_CERT_ERR, FETCH_SSL_ERR } fetch_msg_type; +/** Minimum finished message type. + * + * If a fetch does not progress this far, it's an error and the fetch machinery + * will send FETCH_ERROR to the llcache on fetch_free() + */ +#define FETCH_MIN_FINISHED_MSG FETCH_FINISHED + /** * Fetcher message data */ diff --git a/resources/FatMessages b/resources/FatMessages index 5953574fb..5197ffb7d 100644 --- a/resources/FatMessages +++ b/resources/FatMessages @@ -1133,6 +1133,9 @@ it.all.FetchErrorTitle:Errore durante il recupero della pagina en.all.FetchErrorDescription:An error occurred when connecting to %s it.all.FetchErrorDescription:Si รจ verificato un errore durante la connessione a %s +# Generic fetcher failure (really a programming error) +en.all.FetchFailedToFinish:The fetcher for this request failed to complete + # SSL certificate viewer # ====================== -- cgit v1.2.3