• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

telefonicaid / fiware-orion / 43408076090

13 Nov 2026 10:17AM UTC coverage: 80.401% (+3.4%) from 76.998%
43408076090

push

github

web-flow
Merge pull request #4829 from telefonicaid/feature/4827_coverage_lm_traces

Keep LM_T traces in coverage builds

21206 of 27923 branches covered (75.94%)

Branch coverage included in aggregate %.

17323 of 19998 relevant lines covered (86.62%)

114641.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.82
/src/lib/mongoDriver/mongoConnectionPool.cpp
1
/*
2
*
3
* Copyright 2020 Telefonica Investigacion y Desarrollo, S.A.U
4
*
5
* This file is part of Orion Context Broker.
6
*
7
* Orion Context Broker is free software: you can redistribute it and/or
8
* modify it under the terms of the GNU Affero General Public License as
9
* published by the Free Software Foundation, either version 3 of the
10
* License, or (at your option) any later version.
11
*
12
* Orion Context Broker is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
15
* General Public License for more details.
16
*
17
* You should have received a copy of the GNU Affero General Public License
18
* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/.
19
*
20
* For those usages not covered by this license please contact with
21
* iot_support at tid dot es
22
*
23
* Author: Fermín Galán
24
*/
25
#include <mongoc/mongoc.h>
26

27
#include <time.h>
28
#include <semaphore.h>
29
#include <string>
30
#include <vector>
31

32
#include "logMsg/logMsg.h"
33
#include "logMsg/traceLevels.h"
34

35
#include "common/clockFunctions.h"
36
#include "common/string.h"
37
#include "alarmMgr/alarmMgr.h"
38

39
#include "mongoDriver/connectionOperations.h"
40
#include "mongoDriver/safeMongo.h"
41
#include "mongoDriver/mongoConnectionPool.h"
42
#include "mongoDriver/BSONObjBuilder.h"
43

44

45
/* ****************************************************************************
46
*
47
* RECONNECT_RETRIES - number of retries after connect
48
* RECONNECT_DELAY   - number of millisecs to sleep between retries
49
*/
50
#define RECONNECT_RETRIES 100
51
#define RECONNECT_DELAY   1000  // One second
52

53

54

55
/* ****************************************************************************
56
*
57
* MongoConnection -
58
*/
59
typedef struct MongoConnection
60
{
61
  orion::DBConnection  connection;
62
  bool                 free;
63
} MongoConnection;
64

65

66

67
/* ****************************************************************************
68
*
69
* globals -
70
*/
71
static MongoConnection* connectionPool     = NULL;
72
static int              connectionPoolSize = 0;
73
static sem_t            connectionPoolSem;
74
static sem_t            connectionSem;
75
static struct timespec  semWaitingTime     = { 0, 0 };
76
static bool             semStatistics      = false;
77
static int              mongoVersionMayor  = -1;
78
static int              mongoVersionMinor  = -1;
79

80

81

82
/* ****************************************************************************
83
*
84
* orion::mongoVersionGet -
85
*/
86
void orion::mongoVersionGet(int* mayor, int* minor)
48,308 ✔
87
{
88
  *mayor = mongoVersionMayor;
48,308 ✔
89
  *minor = mongoVersionMinor;
48,308 ✔
90
}
48,308 ✔
91

92

93

94
/* ****************************************************************************
95
*
96
* pingConnection -
97
*
98
* return:
99
*   0: ping is ok
100
*   1: ping fails due to auth
101
*   2: ping fails not due to auth
102
*/
103
static int pingConnection(mongoc_client_t* conn, const char* db, bool mtenat)
49,162 ✔
104
{
105
  // MongoDB has a ping command, but we are not using it, as it doesn't not
106
  // provides auth checking when user and pass are empty (it provides auth
107
  // when we have user and pass, but that is not enough).
108
  //
109
  // In addition, note that command and database depend on mtenant. If we
110
  // are in mtenant mode we
111
  // will need at some point to look for all orion* databases, so command to
112
  // ping will be listDatabases in the admin DB. But if we run in not mtenant
113
  // mode listCollections in the default database will suffice
114

115
  std::string  cmdString;
49,162 ✔
116
  std::string  effectiveDb;
49,162 ✔
117

118
  bson_t* ping = bson_new();
49,162 ✔
119
  if (mtenat)
49,162 ✔
120
  {
121
    cmdString = "listDatabases";
1,520 ✔
122
    BSON_APPEND_INT32(ping, "listDatabases", 1);
1,520 ✔
123
    BSON_APPEND_BOOL(ping, "nameOnly", true);
1,520 ✔
124
    effectiveDb = "admin";
1,520 ✔
125
  }
126
  else
127
  {
128
    cmdString = "listCollections";
47,642 ✔
129
    BSON_APPEND_INT32(ping, "listCollections", 1);
47,642 ✔
130
    effectiveDb = db;
47,642 ✔
131
  }
132
  mongoc_database_t* database = mongoc_client_get_database(conn, effectiveDb.c_str());
49,162 ✔
133

134
  bson_error_t error;
135
  int r = 0;
49,162 ✔
136
  if (!mongoc_database_command_with_opts(database, ping, NULL, NULL, NULL, &error))
49,162 !
137
  {
138
    LM_T(LmtMongo, ("ping command (%s at db %s) falied: %s", cmdString.c_str(), effectiveDb.c_str(), error.message));
×
139
    // Reference error message: Authentication failed
140
    // Reference error message: command listCollections requires authentication
141
    if ((strstr(error.message, "Authentication failed") != NULL) || (strstr(error.message, "requires authentication") != NULL)) {
×
142
      r = 1;
×
143
    }
144
    else
145
    {
146
      r = 2;
×
147
    }
148
  }
149

150
  mongoc_database_destroy(database);
49,162 ✔
151
  bson_destroy(ping);
49,162 ✔
152

153
  return r;
49,162 ✔
154
}
49,162 ✔
155

156

157

158
/* ****************************************************************************
159
*
160
* mongoConnect -
161
*
162
*/
163
static orion::DBConnection mongoConnect
49,162 ✔
164
(
165
  const std::string  mongoUri,
166
  const char*        db,
167
  bool               mtenant,
168
  int                writeConcern
169
)
170
{
171
  // Old C++ legacy driver establishes connection at connection object
172
  // creation time. Note that the C driver behaves different.
173
  // From http://mongoc.org/libmongoc/current/connection-pooling.html#single-mode
174
  // "the client connects on demand when your program first uses it for a MongoDB operation".
175
  // Thus, we are using a ping command just to "stimulate" the connection
176
  //
177
  // FIXME #3789: does this make sense makes sense or should we just to create the
178
  // connection object here and let if fail (if necessary) in its first use? Note
179
  // current implemetation tries to use a similar approach (reconnection loop)
180
  // as Orion 2.6.0 did, but maybe this is completely unnecessary if we move
181
  // to native pool management in the C driver
182

183
  bool connected = false;
49,162 ✔
184
  mongoc_client_t* conn;
185
  for (int tryNo = 0; tryNo < RECONNECT_RETRIES; ++tryNo)
49,162 !
186
  {
187
    conn = mongoc_client_new(mongoUri.c_str());
49,162 ✔
188
    if (conn == NULL)
49,162 !
189
    {
190
      // If URI is wrong it is wrong for all the attemps: we early end in this case
191
      LM_E(("Database Startup Error (mongoUri is wrong: <%s>)", mongoUri.c_str()));
×
192
      return orion::DBConnection(NULL);
×
193
    }
194

195
    int check = pingConnection(conn, db, mtenant);
49,162 ✔
196

197
    if (check == 0)
49,162 !
198
    {
199
      // Connection ok
200
      connected = true;
49,162 ✔
201
      break;
49,162 ✔
202
    }
203
    else if (check == 1)
×
204
    {
205
      // Connection fails due to auth
206
      LM_E(("Database Startup Error (auth failed)"));
×
207
      mongoc_client_destroy(conn);
×
208
      return orion::DBConnection(NULL);
×
209
    }
210
    else  // check == 2
211
    {
212
      LM_T(LmtMongo, ("Try %d connecting to mongo failed", tryNo));
×
213
      usleep(RECONNECT_DELAY * 1000);  // usleep accepts microseconds
×
214
    }
215
  }
216

217
  if (!connected)
49,162 !
218
  {
219
    LM_E(("Database Startup Error (cannot connect to mongo - doing %d retries with a %d millisecond interval)",
×
220
          RECONNECT_RETRIES,
221
          RECONNECT_DELAY));
222
    mongoc_client_destroy(conn);
×
223
    return orion::DBConnection(NULL);
×
224
  }
225

226
  //
227
  // WriteConcern
228
  //
229
  // Alternatively, write concern could be established as part of the mongoUri,
230
  // see https://docs.mongodb.com/manual/reference/connection-string/#write-concern-options
231
  //
232
  mongoc_write_concern_t* wc = mongoc_write_concern_new();
49,162 ✔
233
  if (writeConcern == 0)
49,162 !
234
  {
235
    LM_T(LmtMongo, ("connection created with Write Concern: 0"));
×
236
    mongoc_write_concern_set_w(wc, MONGOC_WRITE_CONCERN_W_UNACKNOWLEDGED);
×
237
  }
238
  else   // writeConcern == 1
239
  {
240
    LM_T(LmtMongo, ("connection created with Write Concern: 1"));
49,162 ✔
241
    mongoc_write_concern_set_w(wc, MONGOC_WRITE_CONCERN_W_DEFAULT);
49,162 ✔
242
  }
243

244
  mongoc_client_set_write_concern(conn, wc);
49,162 ✔
245

246
  mongoc_write_concern_destroy(wc);
49,162 ✔
247

248
  return orion::DBConnection(conn);
49,162 ✔
249
}
250

251

252

253
/* ****************************************************************************
254
*
255
* shutdownClient -
256
*/
257
static void shutdownClient(void)
4,918 ✔
258
{
259
  LM_T(LmtMongo, ("shutdown mongo client"));
4,918 ✔
260

261
  for (int ix = 0; ix < connectionPoolSize; ++ix)
54,078 ✔
262
  {
263
    if (!connectionPool[ix].connection.isNull())
49,160 !
264
    {
265
      // Setting free to false is a safe guard when the shutdown process
266
      // takes too much (which is not usual when MongoDB runs locally to CB
267
      // but it may happend with some probability when MongoDB runs on the cloud).
268
      // Otherwise, the cache refresh process could start and use a destroyed connection
269
      // (thus causing segfault)
270
      LM_T(LmtMongo, ("closing connection #%d", ix));
49,160 ✔
271
      connectionPool[ix].free = false;
49,160 ✔
272
      mongoc_client_destroy(connectionPool[ix].connection.get());
49,160 ✔
273
    }
274
  }
275
  mongoc_cleanup();
4,918 ✔
276
}
4,918 ✔
277

278

279

280
/* ****************************************************************************
281
*
282
* mongoDriverLogger -
283
*/
284
static void mongoDriverLogger
×
285
(
286
  mongoc_log_level_t  log_level,
287
  const char          *log_domain,
288
  const char          *message,
289
  void                *user_data
290
)
291
{
292
  // FIXME P3: user_data is needed due to the handler signature, but don't know
293
  // what do to with it
294

295
  // Match driver errors to our own log levels
296
  switch (log_level)
×
297
  {
298
  case MONGOC_LOG_LEVEL_CRITICAL:
×
299
  case MONGOC_LOG_LEVEL_ERROR:
300
    LM_E(("mongoc driver: <%s> <%s>", log_domain, message));
×
301
    break;
×
302
  case MONGOC_LOG_LEVEL_WARNING:
×
303
  case MONGOC_LOG_LEVEL_MESSAGE:
304
  case MONGOC_LOG_LEVEL_INFO:
305
  case MONGOC_LOG_LEVEL_DEBUG:
306
  case MONGOC_LOG_LEVEL_TRACE:
307
    LM_W(("mongoc driver: <%s> <%s>", log_domain, message));
×
308
    break;
×
309
  }
310
}
×
311

312

313

314
/* ****************************************************************************
315
*
316
* composeMongoUri -
317
*/
318
static std::string composeMongoUri(const char*  dbURI, const char*  passwd)
4,918 ✔
319
{
320
  // Compose the mongoUri, taking into account all information
321

322
  std::string uri;
4,918 ✔
323

324
  const char* pwd = strstr(dbURI, "${PWD}");
4,918 ✔
325
  if (pwd != NULL)
4,918 !
326
  {
327
    if (strlen(passwd) == 0)
×
328
    {
329
      LM_X(1, ("Invalid Command Line Options: -dbURI is used with a password substitution, but no password (-dbpwd) is supplied"));
×
330
    }
331

332
    // +6 is the length of the "${PWD}"
333
    uri = std::string(dbURI, pwd - dbURI) + passwd + (pwd + 6);
×
334
  }
335
  else
336
  {
337
    uri = dbURI;
4,918 ✔
338
  }
339
  
340
  LM_T(LmtMongo, ("MongoDB connection URI: '%s'", offuscatePassword(uri, passwd).c_str()));
13,066 ✔
341

342
  return uri;
4,918 ✔
343
}
×
344

345

346

347
/* ****************************************************************************
348
*
349
* orion::mongoConnectionPoolInit -
350
*/
351
int orion::mongoConnectionPoolInit
4,918 ✔
352
(
353
  const char*  dbURI,
354
  const char*  db,
355
  const char*  passwd,
356
  bool         mtenant,
357
  int          writeConcern,
358
  int          poolSize,
359
  bool         semTimeStat
360
)
361
{
362
  // Contrary to intuition (as you would expect that mongoc_init is the very first
363
  // driver function you have to call :) the mongoc_log_set_handler function
364
  // has to be called *before* or some problems with some traces will occur.
365
  // Details at: https://jira.mongodb.org/browse/CDRIVER-3904
366

367
  // Ref: http://mongoc.org/libmongoc/current/logging.html
368
  mongoc_log_set_handler(mongoDriverLogger, NULL);
4,918 ✔
369

370
  mongoc_init();
4,918 ✔
371

372
  atexit(shutdownClient);
4,918 ✔
373

374
  // Set mongo Uri to connect
375
  std::string uri = composeMongoUri(dbURI, passwd);
4,918 ✔
376

377
#ifdef UNIT_TEST
378
  /* Basically, we are mocking all the DB pool with a single connection. The getMongoConnection() and mongoReleaseConnection() methods
379
   * are mocked in similar way to ensure a coherent behaviour */
380
  orion::setMongoConnectionForUnitTest(mongoConnect(uri, db, mtenant, writeConcern));
2 ✔
381
  return 0;
2 ✔
382
#else
383
  //
384
  // Create the pool
385
  //
386
  connectionPool = (MongoConnection*) calloc(sizeof(MongoConnection), poolSize);
4,916 ✔
387
  if (connectionPool == NULL)
4,916 !
388
  {
389
    LM_E(("Runtime Error (insufficient memory to create connection pool of %d connections)", poolSize));
×
390
    return -1;
×
391
  }
392
  connectionPoolSize = poolSize;
4,916 ✔
393

394
  //
395
  // Initialize (connect) the pool
396
  //
397
  for (int ix = 0; ix < connectionPoolSize; ++ix)
54,076 ✔
398
  {
399
    connectionPool[ix].free       = true;
49,160 ✔
400
    connectionPool[ix].connection = mongoConnect(uri, db, mtenant, writeConcern);
49,160 ✔
401

402
    if (connectionPool[ix].connection.isNull())
49,160 !
403
    {
404
      return -1;
×
405
    }
406
  }
407

408
  //
409
  // Set up the semaphore protecting the pool itself (connectionPoolSem)
410
  //
411
  int r = sem_init(&connectionPoolSem, 0, 1);
4,916 ✔
412

413
  if (r != 0)
4,916 !
414
  {
415
    LM_E(("Runtime Error (cannot create connection pool semaphore)"));
×
416
    return -1;
×
417
  }
418

419
  //
420
  // Set up the semaphore protecting the set of connections of the pool (connectionSem)
421
  // Note that this is a counting semaphore, initialized to connectionPoolSize.
422
  //
423
  r = sem_init(&connectionSem, 0, connectionPoolSize);
4,916 ✔
424
  if (r != 0)
4,916 !
425
  {
426
    LM_E(("Runtime Error (cannot create connection semaphore-set)"));
×
427
    return -1;
×
428
  }
429

430
  // Measure accumulated semaphore waiting time?
431
  semStatistics = semTimeStat;
4,916 ✔
432

433
  /* Get mongo version with the 'buildinfo' command */
434
  orion::BSONObj  result;
4,916 ✔
435
  std::string     extra;
4,916 ✔
436
  std::string     err;
4,916 ✔
437

438
  orion::BSONObjBuilder bob;
4,916 ✔
439
  bob.append("buildinfo", 1);
4,916 ✔
440

441
  if (!orion::runDatabaseCommand("admin", bob.obj(), &result, &err))
14,748 !
442
  {
443
    LM_X(1, ("Fatal Error (error getting MongoDB server version: %s)", err.c_str()));
×
444
  }
445

446
  std::string versionString = std::string(getStringFieldF(result, "version"));
14,748 ✔
447
  if (!versionParse(versionString, mongoVersionMayor, mongoVersionMinor, extra))
4,916 !
448
  {
449
    LM_X(1, ("Fatal Error (MongoDB invalid version format: <%s>)", versionString.c_str()));
×
450
  }
451
  LM_T(LmtMongo, ("mongo version server: %s (mayor: %d, minor: %d, extra: %s)",
4,916 ✔
452
                  versionString.c_str(),
453
                  mongoVersionMayor,
454
                  mongoVersionMinor,
455
                  extra.c_str()));
456

457
  LM_I(("Connected to %s (dbName: %s, poolsize: %d)", offuscatePassword(uri, passwd).c_str(), db, poolSize));
14,732 ✔
458

459
  return 0;
4,916 ✔
460
#endif
461
}
4,918 ✔
462

463

464

465
/* ****************************************************************************
466
*
467
* mongoPoolConnectionGet -
468
*
469
* There are two semaphores to get a connection.
470
* - One binary semaphore that protects the connection-vector itself (connectionPoolSem)
471
* - One counting semaphore that makes the caller wait until there is at least one free connection (connectionSem)
472
*
473
* There is a limited number of connections and the first thing to do is to wait for a connection
474
* to become avilable (any of the N connections in the pool) - this is done waiting on the counting semaphore that is
475
* initialized with "POOL SIZE" - meaning the semaphore can be taken N times if the pool size is N.
476
*
477
* Once a connection is free, 'sem_wait(&connectionSem)' returns and we now have to take the semaphore
478
* that protects for pool itself (we *are* going to modify the vector of the pool - can only do it in
479
* one thread at a time ...)
480
*
481
* After taking a connection, the semaphore 'connectionPoolSem' is freed, as all modifications to the connection pool
482
* have finished.
483
* The other semaphore however, 'connectionSem', is kept and it is not freed until we finish using the connection.
484
*
485
* The function mongoPoolConnectionRelease releases the counting semaphore 'connectionSem'.
486
* Very important to call the function 'mongoPoolConnectionRelease' after finishing using the connection !
487
*
488
*/
489
static orion::DBConnection mongoPoolConnectionGet(void)
174,304 ✔
490
{
491
  orion::DBConnection connection;
174,304 ✔
492
  struct timespec     startTime;
493
  struct timespec     endTime;
494
  struct timespec     diffTime;
495

496
  if (semStatistics)
174,304 ✔
497
  {
498
    clock_gettime(CLOCK_REALTIME, &startTime);
14 ✔
499
  }
500

501
  sem_wait(&connectionSem);
174,304 ✔
502
  sem_wait(&connectionPoolSem);
174,304 ✔
503

504
  if (semStatistics)
174,304 ✔
505
  {
506
    clock_gettime(CLOCK_REALTIME, &endTime);
14 ✔
507

508
    clock_difftime(&endTime, &startTime, &diffTime);
14 ✔
509
    clock_addtime(&semWaitingTime, &diffTime);
14 ✔
510
  }
511

512
  for (int ix = 0; ix < connectionPoolSize; ++ix)
177,687 ✔
513
  {
514
    if (connectionPool[ix].free == true)
177,645 ✔
515
    {
516
      connectionPool[ix].free = false;
174,262 ✔
517
      connection = connectionPool[ix].connection;
174,262 ✔
518
      break;
174,262 ✔
519
    }
520
  }
521

522
  sem_post(&connectionPoolSem);
174,304 ✔
523

524
  return connection;
174,304 ✔
525
}
526

527

528
#ifndef UNIT_TEST
529
/* ****************************************************************************
530
*
531
* mongoPoolConnectionRelease -
532
*/
533
static void mongoPoolConnectionRelease(const orion::DBConnection& connection)
174,304 ✔
534
{
535
  sem_wait(&connectionPoolSem);
174,304 ✔
536

537
  for (int ix = 0; ix < connectionPoolSize; ++ix)
177,687 ✔
538
  {
539
    if (connectionPool[ix].connection == connection)
177,645 ✔
540
    {
541
      connectionPool[ix].free = true;
174,262 ✔
542
      sem_post(&connectionSem);
174,262 ✔
543
      break;
174,262 ✔
544
    }
545
  }
546

547
  sem_post(&connectionPoolSem);
174,304 ✔
548
}
174,304 ✔
549
#endif
550

551

552

553
/* ****************************************************************************
554
*
555
* orion::mongoPoolConnectionSemWaitingTimeGet -
556
*/
557
float orion::mongoPoolConnectionSemWaitingTimeGet(void)
8 ✔
558
{
559
  return semWaitingTime.tv_sec + ((float) semWaitingTime.tv_nsec) / 1E9;
8 ✔
560
}
561

562

563

564
/* ****************************************************************************
565
*
566
* orion::mongoPoolConnectionSemWaitingTimeReset -
567
*/
568
void orion::mongoPoolConnectionSemWaitingTimeReset(void)
2 ✔
569
{
570
  semWaitingTime.tv_sec  = 0;
2 ✔
571
  semWaitingTime.tv_nsec = 0;
2 ✔
572
}
2 ✔
573

574

575

576
/* ****************************************************************************
577
*
578
* orion::mongoConnectionPoolSemGet -
579
*/
580
const char* orion::mongoConnectionPoolSemGet(void)
8 ✔
581
{
582
  int value;
583

584
  if (sem_getvalue(&connectionPoolSem, &value) == -1)
8 !
585
  {
586
    return "error";
×
587
  }
588

589
  if (value == 0)
8 !
590
  {
591
    return "taken";
×
592
  }
593

594
  return "free";
8 ✔
595
}
596

597

598

599
/* ****************************************************************************
600
*
601
* orion::mongoConnectionSemGet -
602
*/
603
const char* orion::mongoConnectionSemGet(void)
8 ✔
604
{
605
  int value;
606

607
  if (sem_getvalue(&connectionSem, &value) == -1)
8 !
608
  {
609
    return "error";
×
610
  }
611

612
  if (value == 0)
8 !
613
  {
614
    return "taken";
×
615
  }
616

617
  return "free";
8 ✔
618
}
619

620

621

622
#ifdef UNIT_TEST
623

624
static orion::DBConnection connection;
625

626

627

628
/* ****************************************************************************
629
*
630
* orion::setMongoConnectionForUnitTest -
631
*
632
* For unit tests there is only one connection. This connection is stored right here (orion::DBConnection* connection) and
633
* given out using the function getMongoConnection().
634
*/
635
void orion::setMongoConnectionForUnitTest(orion::DBConnection _connection)
2 ✔
636
{
637
  connection = _connection;
2 ✔
638
}
2 ✔
639

640

641

642
/* ****************************************************************************
643
*
644
* mongoInitialConnectionGetForUnitTest -
645
*
646
* This function is meant to be used by unit tests, to get a connection from the pool
647
* and then use that connection, setting it with the function 'orion::setMongoConnectionForUnitTest'.
648
* This will set the static variable 'connection' in MongoGlobal.cpp and later 'getMongoConnection'
649
* returns that variable (getMongoConnection is used by the entire mongo backend).
650
*/
651
orion::DBConnection mongoInitialConnectionGetForUnitTest(void)
×
652
{
653
  return mongoPoolConnectionGet();
×
654
}
655
#endif
656

657

658

659
/* ****************************************************************************
660
*
661
* orion::getMongoConnection -
662
*
663
* I would prefer to have per-collection methods, to have a better encapsulation, but
664
* the Mongo C++ API doesn't seem to work that way
665
*/
666
orion::DBConnection orion::getMongoConnection(void)
174,304 ✔
667
{
668
#ifdef UNIT_TEST
669
  return connection;
×
670
#else
671
  return mongoPoolConnectionGet();
174,304 ✔
672
#endif
673
}
674

675

676

677
/* ****************************************************************************
678
*
679
* releaseMongoConnection - give back mongo connection to connection pool
680
*
681
* Older versions of this function planned to use a std::auto_ptr<DBClientCursor>* parameter
682
* in order to invoke kill() on it for a "safer" connection releasing. However, at the end
683
* it seems that kill() will not help at all (see deetails in https://github.com/telefonicaid/fiware-orion/issues/1568)
684
* and after some testing we have checked that the current solution is stable.
685
*/
686
void orion::releaseMongoConnection(const orion::DBConnection& connection)
174,304 ✔
687
{
688
#ifdef UNIT_TEST
689
  return;
×
690
#else
691
  return mongoPoolConnectionRelease(connection);
174,304 ✔
692
#endif  // UNIT_TEST
693
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc