Skip to content

Commit

Permalink
Hopefully fixed issue #1419
Browse files Browse the repository at this point in the history
  • Loading branch information
kzangeli committed Aug 30, 2023
1 parent 6d08fac commit 70d1bad
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
2 changes: 2 additions & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Fixed issues:
* #1419 - Fixed a bug in the cleanup of the "URL being downloaded list" - not being cleaned up in case of an error
* #280 - Added extensive logging for downloading of contexts
2 changes: 2 additions & 0 deletions src/lib/orionld/common/orionldRequestSend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ static size_t writeCallback(void* contents, size_t size, size_t members, void* u
OrionldResponseBuffer* rBufP = (OrionldResponseBuffer*) userP;
int xtraBytes = 512;

LM_T(LmtCurl, ("CURL: got %d bytes of payload body: %s", bytesToCopy, contents));

if (bytesToCopy + rBufP->used >= rBufP->size)
{
if (rBufP->buf == rBufP->internalBuffer)
Expand Down
34 changes: 15 additions & 19 deletions src/lib/orionld/context/orionldContextFromUrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,34 +316,30 @@ OrionldContext* orionldContextFromUrl(char* url, char* id)

LM_T(LmtContextDownload, ("Downloading the context '%s' and adding it to the context cache", url));
char* buffer = orionldContextDownload(url); // orionldContextDownload fills in ProblemDetails
if (buffer == NULL)
return NULL;

LM_T(LmtCoreContext, ("Downloaded the context '%s'", url));
contextP = orionldContextFromBuffer(url, OrionldContextDownloaded, id, buffer);
if (contextP == NULL)
if (buffer != NULL) // All OK
{
//
// Uncomfortable problem here ...
// The downloaded @context is erroneous and cannot be used.
// The response to the request indicates this fact, but, if the client
// insists on trying to use the context (without fixing it), the broker will download it over and over again.
// Still, I believe this is the best solution.
//
LM_E(("Context Error (%s: %s)", orionldState.pd.title, orionldState.pd.detail));
contextDownloadListRemove(url);
return NULL; // Parse Error?
LM_T(LmtCoreContext, ("Downloaded the context '%s'", url));
contextP = orionldContextFromBuffer(url, OrionldContextDownloaded, id, buffer);
if (contextP == NULL)
LM_E(("Context Error (%s: %s)", orionldState.pd.title, orionldState.pd.detail));
}
else
LM_E(("Context Error (%s: %s)", orionldState.pd.title, orionldState.pd.detail));

contextP->origin = OrionldContextDownloaded;
contextP->createdAt = orionldState.requestTime;
contextP->usedAt = orionldState.requestTime;
if (contextP != NULL)
{
contextP->origin = OrionldContextDownloaded;
contextP->createdAt = orionldState.requestTime;
contextP->usedAt = orionldState.requestTime;

orionldContextCachePersist(contextP);
}

// Remove the 'url' from the contextDownloadList and persist it to DB
sem_wait(&contextDownloadListSem);
contextDownloadListRemove(url);
sem_post(&contextDownloadListSem);
orionldContextCachePersist(contextP);

return contextP;
}

0 comments on commit 70d1bad

Please sign in to comment.