From 5571604d4d7bc0a64751f68687e3cc6cbe658f5f Mon Sep 17 00:00:00 2001 From: George Alexiou Date: Tue, 30 Jan 2024 13:14:40 +0000 Subject: [PATCH] FIX -dbTimeout conflict with -dbURI --- src/app/contextBroker/contextBroker.cpp | 4 ++-- src/lib/mongoDriver/mongoConnectionPool.cpp | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/app/contextBroker/contextBroker.cpp b/src/app/contextBroker/contextBroker.cpp index bf81abec8f..2232e25c3e 100644 --- a/src/app/contextBroker/contextBroker.cpp +++ b/src/app/contextBroker/contextBroker.cpp @@ -309,8 +309,8 @@ PaArgument paArgs[] = { "-dbDisableRetryWrites", &dbDisableRetryWrites, "MONGO_DISABLE_RETRY_WRITES", PaBool, PaOpt, false, false, true, DBDISABLERETRYWRITES_DESC }, { "-db", dbName, "MONGO_DB", PaString, PaOpt, _i "orion", PaNL, PaNL, DB_DESC }, - { "-dbTimeout", &dbTimeout, "MONGO_TIMEOUT", PaULong, PaOpt, 10000, 0, UINT_MAX, DB_TMO_DESC }, - { "-dbPoolSize", &dbPoolSize, "MONGO_POOL_SIZE", PaInt, PaOpt, 10, 1, 10000, DBPS_DESC }, + { "-dbTimeout", &dbTimeout, "MONGO_TIMEOUT", PaULong, PaOpt, -1, -1, UINT_MAX, DB_TMO_DESC }, + { "-dbPoolSize", &dbPoolSize, "MONGO_POOL_SIZE", PaInt, PaOpt, 10, 1, 10000, DBPS_DESC }, { "-ipv4", &useOnlyIPv4, "USEIPV4", PaBool, PaOpt, false, false, true, USEIPV4_DESC }, { "-ipv6", &useOnlyIPv6, "USEIPV6", PaBool, PaOpt, false, false, true, USEIPV6_DESC }, diff --git a/src/lib/mongoDriver/mongoConnectionPool.cpp b/src/lib/mongoDriver/mongoConnectionPool.cpp index ed0d1db07c..d086c0ffa6 100644 --- a/src/lib/mongoDriver/mongoConnectionPool.cpp +++ b/src/lib/mongoDriver/mongoConnectionPool.cpp @@ -334,7 +334,7 @@ static std::string composeMongoUri if (strlen(dbURI) != 0) { - if (strlen(username) != 0 || strlen(authDb) != 0 || strlen(rplSet) != 0 || strlen(mechanism) != 0 || dbSSL || dbDisableRetryWrites || timeout > 0) + if (strlen(username) != 0 || strlen(authDb) != 0 || strlen(rplSet) != 0 || strlen(mechanism) != 0 || dbSSL || dbDisableRetryWrites || timeout > -1) { LM_X(1, ("Invalid Command Line Options: -dbURI cannot be combined with -dbhost, -rplSet, -dbTimeout, -dbuser, -dbAuthMech, -dbAuthDb, -dbSSL and -dbDisableRetryWrites")); } @@ -399,14 +399,20 @@ static std::string composeMongoUri optionPrefix = "&"; } - if (timeout > 0) + // Check if timeout is not zero (which means it's either unset or explicitly set to a positive value) + if (timeout != 0) { - char buf[STRING_SIZE_FOR_LONG]; - i2s(timeout, buf, sizeof(buf)); - uri += optionPrefix + "connectTimeoutMS=" + buf; - optionPrefix = "&"; + // If timeout is negative (e.g., -1 indicating it's unset), set it to the default value of 10000 + if (timeout < 0) + { + timeout = 10000; + } + + char buf[STRING_SIZE_FOR_LONG]; + i2s(timeout, buf, sizeof(buf)); + uri += optionPrefix + "connectTimeoutMS=" + buf; + optionPrefix = "&"; } - } LM_T(LmtMongo, ("MongoDB connection URI: '%s'", offuscatePassword(uri, passwd).c_str()));