diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 2542f9d4c..45b46a272 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1 +1,2 @@ -- Upgrade mongoose dep from 5.13.14 to 5.13.20 +- Fix: Payload measures are lost after reconnection with Orion (#1407) +- Upgrade mongoose dep from 5.13.14 to 5.13.20 diff --git a/config.js b/config.js index 3542fc7e2..ab9967dc4 100644 --- a/config.js +++ b/config.js @@ -76,7 +76,9 @@ var config = { subservice: '/gardens', providerUrl: 'http://192.168.56.1:4041', deviceRegistrationDuration: 'P1M', - defaultType: 'Thing' + defaultType: 'Thing', + ORION_DEFAULT_RETRIES: 5, + ORION_DEFAULT_RETRY_TIME: 5 }; module.exports = config; diff --git a/doc/deprecated.md b/doc/deprecated.md index 82f88f804..2b3348ebb 100644 --- a/doc/deprecated.md +++ b/doc/deprecated.md @@ -43,15 +43,15 @@ information in the case you want to use old versions: The following table provides information about the last iotagent-node-lib version supporting currently removed features: -| **Removed feature** | **Last iotagent-node-lib version supporting feature** | **That version release date** | -| ---------------------- | ----------------------------------------------------- | ----------------------------- | -| NGSI v1 API | 2.17.0 | August 30th, 2021 | -| Support to Node.js v4 | 2.8.1 | December 19th, 2018 | -| Support to Node.js v6 | 2.9.0 | May 22nd, 2019 | -| Support to Node.js v8 | 2.12.0 | April 7th, 2020 | -| Support to Node.js v10 | 2.15.0 | February 18th, 2021 | -| Support to Node.js v12 | 2.24.0 | September 2nd, 2022 | -| Support to NGSI-LD 1.3 | 2.25.0 | January 24th, 2023 | -| Support to Legacy Expressions | 3.1.0 | April 25th, 2023 | -| bidirrectional plugin | 3.3.0 | August 24th, 2023 | -| appendMode | 3.3.0 | August 24th, 2023 | +| **Removed feature** | **Last iotagent-node-lib version supporting feature** | **That version release date** | +| ----------------------------- | ----------------------------------------------------- | ----------------------------- | +| NGSI v1 API | 2.17.0 | August 30th, 2021 | +| Support to Node.js v4 | 2.8.1 | December 19th, 2018 | +| Support to Node.js v6 | 2.9.0 | May 22nd, 2019 | +| Support to Node.js v8 | 2.12.0 | April 7th, 2020 | +| Support to Node.js v10 | 2.15.0 | February 18th, 2021 | +| Support to Node.js v12 | 2.24.0 | September 2nd, 2022 | +| Support to NGSI-LD 1.3 | 2.25.0 | January 24th, 2023 | +| Support to Legacy Expressions | 3.1.0 | April 25th, 2023 | +| bidirrectional plugin | 3.3.0 | August 24th, 2023 | +| appendMode | 3.3.0 | August 24th, 2023 | diff --git a/lib/request-shim.js b/lib/request-shim.js index f1aab860e..e76f6213b 100644 --- a/lib/request-shim.js +++ b/lib/request-shim.js @@ -20,7 +20,7 @@ * For those usages not covered by the GNU Affero General Public License * please contact with::daniel.moranjimenez@telefonica.com */ - +const config = require('../config'); const got = require('got'); const logger = require('logops'); const context = { @@ -95,17 +95,36 @@ function getOptions(options) { * */ +let retryCount = 0; //default retry_count value function request(options, callback) { + const retryTime = config.ORION_DEFAULT_RETRY_TIME; + const retries = config.ORION_DEFAULT_RETRIES; const httpOptions = getOptions(options); logger.debug(context, 'Options: %s', JSON.stringify(options, null, 4)); got(options.url || options.uri, httpOptions) .then((response) => { logger.debug(context, 'Response %s', JSON.stringify(response.body, null, 4)); + retryCount = 0; return callback(null, response, response.body); }) .catch((error) => { - logger.debug(context, 'Error: %s', JSON.stringify(util.inspect(error), null, 4)); - return callback(error); + if (error.code === 'ECONNREFUSED') { + if (retryCount < retries) { + retryCount++; + console.log('Retrying connection', JSON.stringify(retryCount)); + return setTimeout(request, retryTime * 1000 , options, callback); + } + //retrun the error + else { + retryCount = 0; + logger.debug(context, 'Error: %s', JSON.stringify(util.inspect(error), null, 4)); + return callback(error); + } + } + else{ + logger.debug(context, 'Error: %s', JSON.stringify(util.inspect(error), null, 4)); + return callback(error); + } }); }