Skip to content

Commit

Permalink
Merge pull request #287 from liulanzheng/main
Browse files Browse the repository at this point in the history
registry: enhanced error handling
  • Loading branch information
yuchen0cc authored Nov 14, 2023
2 parents 319597c + 923ed10 commit 3dc16b2
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/overlaybd/registryfs/registryfs_v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ class RegistryFSImpl_v2 : public RegistryFS {
op.retry = 0;
op.timeout = tmo.timeout();
m_client->call(&op);

if (op.status_code == 200 || op.status_code == 206) {
ret = op.status_code;
if (ret == 200 || ret == 206) {
m_url_info.release(url);
return ret;
}
Expand Down Expand Up @@ -212,17 +212,18 @@ class RegistryFSImpl_v2 : public RegistryFS {
op.req.headers.value_append(*token);
op.timeout = tmo.timeout();
op.call();
if (op.status_code == 401 || op.status_code == 403) {
code = op.status_code;
if (code == 401 || code == 403) {
LOG_WARN("Token invalid, try refresh password next time");
}
if (300 <= op.status_code && op.status_code < 400) {
if (300 <= code && code < 400) {
// pass auth, redirect to source
auto location = op.resp.headers["Location"];
if (!scope.empty())
m_scope_token.release(scope);
return new UrlInfo{UrlMode::Redirect, location};
}
if (op.status_code == 200) {
if (code == 200) {
UrlInfo *info = new UrlInfo{UrlMode::Self, ""};
if (token && !token->empty())
info->info = kBearerAuthPrefix + *token;
Expand All @@ -234,7 +235,7 @@ class RegistryFSImpl_v2 : public RegistryFS {
// unexpected situation
if (!scope.empty())
m_scope_token.release(scope, true);
LOG_ERROR_RETURN(0, nullptr, "Failed to get actual url, status_code=` ", op.status_code, VALUE(url));
LOG_ERROR_RETURN(0, nullptr, "Failed to get actual url, status_code=` ", code, VALUE(url));
}

virtual int setAccelerateAddress(const char* addr = "") override {
Expand Down Expand Up @@ -403,15 +404,15 @@ class RegistryFileImpl_v2 : public photon::fs::VirtualReadOnlyFile {
LOG_DEBUG("pulling blob from registry: ", VALUE(m_url), VALUE(offset), VALUE(count));

HTTP_OP op;
auto ret = m_fs->get_data(m_url, offset, count, tmo.timeout(), op);
if (op.status_code != 200 && op.status_code != 206) {
auto code = m_fs->get_data(m_url, offset, count, tmo.timeout(), op);
if (code != 200 && code != 206) {
ERRNO eno;
if (tmo.expire() < photon::now) {
LOG_ERROR_RETURN(ETIMEDOUT, -1, "timed out in preadv ", VALUE(m_url), VALUE(offset));
}
if (retry--) {
LOG_WARN("failed to perform HTTP GET, going to retry ", VALUE(op.status_code), VALUE(offset),
VALUE(count), VALUE(ret), eno);
LOG_WARN("failed to perform HTTP GET, going to retry ", VALUE(code), VALUE(offset),
VALUE(count), eno);
photon::thread_usleep(1000);
goto again;
} else {
Expand All @@ -427,18 +428,19 @@ class RegistryFileImpl_v2 : public photon::fs::VirtualReadOnlyFile {
int retry = 3;
again:
HTTP_OP op;
auto ret = m_fs->get_data(m_url, 0, 1, tmo.timeout(), op);
if (op.status_code != 200 && op.status_code != 206) {
auto code = m_fs->get_data(m_url, 0, 1, tmo.timeout(), op);
if (code != 200 && code != 206) {
if (tmo.expire() < photon::now)
LOG_ERROR_RETURN(ETIMEDOUT, -1, "get meta timedout");

if (op.status_code == 401 || op.status_code == 403) {
if (retry--)
if (retry--)
goto again;
if (code == 401 || code == 403) {
LOG_ERROR_RETURN(EPERM, -1, "Authorization failed");
} else if (code == 404) {
LOG_ERROR_RETURN(ENOENT, -1, "No such file or directory");
} else if (code == 429) {
LOG_ERROR_RETURN(EBUSY, -1, "Too many request");
}
if (retry--)
goto again;
LOG_ERROR_RETURN(ENOENT, -1, "failed to get meta from server");
}
return op.resp.resource_size();
Expand Down

0 comments on commit 3dc16b2

Please sign in to comment.