From 7e04901403a0053f67eae6c9bb58764b529c0bd8 Mon Sep 17 00:00:00 2001 From: WangFengTu Date: Tue, 19 Jan 2021 16:57:17 +0800 Subject: [PATCH 10/26] fix ramdom coredump if pull failed Signed-off-by: WangFengTu --- src/daemon/modules/image/oci/registry/registry.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/daemon/modules/image/oci/registry/registry.c b/src/daemon/modules/image/oci/registry/registry.c index 3fba2039..1bb91d0f 100644 --- a/src/daemon/modules/image/oci/registry/registry.c +++ b/src/daemon/modules/image/oci/registry/registry.c @@ -1298,8 +1298,10 @@ static void free_thread_fetch_info(thread_fetch_info *info) return; } -static bool all_fetch_complete(pull_descriptor *desc, int *result) +static bool all_fetch_complete(pull_descriptor *desc, thread_fetch_info *infos, int *result) { + int i = 0; + if (!desc->config.complete) { return false; } @@ -1314,6 +1316,13 @@ static bool all_fetch_complete(pull_descriptor *desc, int *result) return false; } + // wait all fetch threads completed + for (i = 0; i < desc->layers_len; i++) { + if (infos[i].use && !infos[i].notified) { + return false; + } + } + if (desc->cancel) { *result = -1; } @@ -1584,7 +1593,7 @@ static int fetch_all(pull_descriptor *desc) // wait until all pulled or cancelled mutex_lock(&g_shared->mutex); - while (!all_fetch_complete(desc, &result)) { + while (!all_fetch_complete(desc, infos, &result)) { ts.tv_sec = time(NULL) + DEFAULT_WAIT_TIMEOUT; // avoid wait forever cond_ret = pthread_cond_timedwait(&g_shared->cond, &g_shared->mutex, &ts); if (cond_ret != 0 && cond_ret != ETIMEDOUT) { -- 2.25.1