Skip to content

Commit

Permalink
Merge pull request #1548 from FIWARE/bug/issue1499
Browse files Browse the repository at this point in the history
Desperate attempt to fix issue #1499
  • Loading branch information
kzangeli authored Feb 8, 2024
2 parents da204f8 + fd92829 commit 88be9a6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/lib/orionld/mongoc/mongocGeoIndexInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ bool mongocGeoIndexInit(void)
// Get handle to collection
//
mCollectionP = mongoc_client_get_collection(orionldState.mongoc.client, tenantP->mongoDbName, "entities");
if (mCollectionP == NULL)
LM_X(1, ("mongoc_client_get_collection failed for 'entities' collection on tenant '%s'", tenantP->mongoDbName));

// Aggregation pipeline

Expand Down
3 changes: 3 additions & 0 deletions src/lib/orionld/mongoc/mongocRegistrationsIter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ int mongocRegistrationsIter(RegCache* rcP, RegCacheIterFunc callback)
//
mongoc_collection_t* regsCollectionP = mongoc_client_get_collection(orionldState.mongoc.client, rcP->tenantP->mongoDbName, "registrations");

if (regsCollectionP == NULL)
LM_X(1, ("mongoc_client_get_collection failed for 'registrations' collection on tenant '%s'", rcP->tenantP->mongoDbName));

//
// Run the query
//
Expand Down
3 changes: 3 additions & 0 deletions src/lib/orionld/mongoc/mongocSubCachePopulateByTenant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ bool mongocSubCachePopulateByTenant(OrionldTenant* tenantP, bool refresh)
mongoc_client_t* connectionP = mongoc_client_pool_pop(mongocPool);
mongoc_collection_t* subscriptionsP = mongoc_client_get_collection(connectionP, tenantP->mongoDbName, "csubs");

if (subscriptionsP == NULL)
LM_X(1, ("mongoc_client_get_collection failed for 'csubs' collection on tenant '%s'", tenantP->mongoDbName));

//
// Run the query
//
Expand Down
3 changes: 3 additions & 0 deletions src/lib/orionld/mongoc/mongocSubCountersUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ void mongocSubCountersUpdate
bson_t selector;
bson_t inc;

if (subscriptionsP == NULL)
LM_X(1, ("mongoc_client_get_collection failed for 'csubs' collection on tenant '%s'", tenantP->mongoDbName));

bson_init(&reply);
bson_init(&selector);
bson_init(&inc);
Expand Down
28 changes: 22 additions & 6 deletions src/lib/rest/rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,28 @@ static void requestCompleted


//
// Release the connection to mongo - after all notifications have been sent (orionldAlterationsTreat takes care of that)
//
if (orionldState.mongoc.contextsP) mongoc_collection_destroy(orionldState.mongoc.contextsP);
if (orionldState.mongoc.entitiesP) mongoc_collection_destroy(orionldState.mongoc.entitiesP);
if (orionldState.mongoc.subscriptionsP) mongoc_collection_destroy(orionldState.mongoc.subscriptionsP);
if (orionldState.mongoc.registrationsP) mongoc_collection_destroy(orionldState.mongoc.registrationsP);
// Release the connections to mongo - after all notifications have been sent (orionldAlterationsTreat takes care of the notifications)
// NOTE, this "construct" with NULLing the mongoc_collection_t pointers before actually calling mongoc_collection_destroy is a
// desperate attempt to fix the issue #1499.
// If still not enough, perhaps a semaphore to protect.
// It's weird though, these collection pointers are THREAD VARIABLES !!!
// No protection should be needed.
// But, desperate times ...
//
mongoc_collection_t* contextsP = orionldState.mongoc.contextsP;
mongoc_collection_t* entitiesP = orionldState.mongoc.entitiesP;
mongoc_collection_t* subscriptionsP = orionldState.mongoc.subscriptionsP;
mongoc_collection_t* registrationsP = orionldState.mongoc.registrationsP;

orionldState.mongoc.contextsP = NULL;
orionldState.mongoc.entitiesP = NULL;
orionldState.mongoc.subscriptionsP = NULL;
orionldState.mongoc.registrationsP = NULL;

if (contextsP != NULL) mongoc_collection_destroy(contextsP);
if (entitiesP != NULL) mongoc_collection_destroy(entitiesP);
if (subscriptionsP != NULL) mongoc_collection_destroy(subscriptionsP);
if (registrationsP != NULL) mongoc_collection_destroy(registrationsP);

mongocConnectionRelease();

Expand Down

0 comments on commit 88be9a6

Please sign in to comment.