Skip to content

Commit

Permalink
fix: restore mem leak fix #497
Browse files Browse the repository at this point in the history
  • Loading branch information
kalinkrustev committed Jan 23, 2025
1 parent 520438a commit 19c43b1
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 18 deletions.
5 changes: 3 additions & 2 deletions modules/api-svc/src/InboundServer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ const apiSpecs = yaml.load(fs.readFileSync(specPath));

const logExcludePaths = ['/'];
const _validator = new Validate({ logExcludePaths });
let _initialize;

class InboundApi extends EventEmitter {
constructor(conf, logger, cache, validator, wso2) {
super({ captureExceptions: true });
this._conf = conf;
this._cache = cache;
this._initialize = _validator.initialise(apiSpecs, conf);
_initialize ||= _validator.initialise(apiSpecs, conf);

if (conf.validateInboundJws) {
// peerJWSKey is a special config option specifically for Payment Manager for Mojaloop
Expand Down Expand Up @@ -162,7 +163,7 @@ class InboundServer extends EventEmitter {

async start() {
assert(!this._server.listening, 'Server already listening');
await this._initialize;
await _initialize;
await this._api.start();
await new Promise((resolve) => this._server.listen(this._conf.inbound.port, resolve));
this._logger.isInfoEnabled && this._logger.info(`Serving inbound API on port ${this._conf.inbound.port}`);
Expand Down
5 changes: 3 additions & 2 deletions modules/api-svc/src/OutboundServer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const apiSpecs = yaml.load(fs.readFileSync(specPath));
const endpointRegex = /\/.*/g;
const logExcludePaths = ['/'];
const _validator = new Validate({ logExcludePaths });
let _initialize;

class OutboundApi extends EventEmitter {
constructor(conf, logger, cache, validator, metricsClient, wso2, eventProducer, eventLogger) {
Expand All @@ -41,7 +42,7 @@ class OutboundApi extends EventEmitter {
this._conf = conf;
this._cache = cache;
this._metricsClient = metricsClient;
this._initialize = _validator.initialise(apiSpecs, conf);
_initialize ||= _validator.initialise(apiSpecs, conf);

this._api.use(middlewares.createErrorHandler(this._logger));
this._api.use(middlewares.createRequestIdGenerator(this._logger));
Expand Down Expand Up @@ -118,7 +119,7 @@ class OutboundServer extends EventEmitter {
async start() {
const { port } = this._conf.outbound;
await this._eventProducer?.init();
await this._initialize;
await _initialize;
await this._api.start();
await new Promise((resolve) => this._server.listen(port, resolve));
this._logger.isInfoEnabled && this._logger.info(`Serving outbound API on port ${this._conf.outbound.port}`);
Expand Down
5 changes: 3 additions & 2 deletions modules/api-svc/src/TestServer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const middlewares = require('../InboundServer/middlewares');

const logExcludePaths = ['/'];
const _validator = new Validate({ logExcludePaths });
let _initialize;

const getWsIp = (req) => [
req.socket.remoteAddress,
Expand Down Expand Up @@ -175,7 +176,7 @@ class WsServer extends ws.Server {

class TestServer {
constructor({ port, logger, cache, config }) {
this._initialize = _validator.initialise(yaml.load(require('fs').readFileSync(path.join(__dirname, 'api.yaml'))), config);
_initialize ||= _validator.initialise(yaml.load(require('fs').readFileSync(path.join(__dirname, 'api.yaml'))), config);
this._port = port;
this._logger = logger;
this._api = new TestApi(this._logger.push({ component: 'api' }), _validator, cache, config);
Expand All @@ -190,7 +191,7 @@ class TestServer {
return;
}

await this._initialize;
await _initialize;

await this._wsapi.start();

Expand Down
2 changes: 1 addition & 1 deletion modules/outbound-command-event-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"@types/convict": "^6.1.6",
"@types/express": "^5.0.0",
"@types/jest": "^29.5.14",
"@types/node": "^22.10.9",
"@types/node": "^22.10.10",
"@types/node-cache": "^4.2.5",
"@types/supertest": "^6.0.2",
"@types/swagger-ui-express": "4.1.7",
Expand Down
2 changes: 1 addition & 1 deletion modules/outbound-domain-event-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"@types/convict": "^6.1.6",
"@types/express": "^5.0.0",
"@types/jest": "^29.5.14",
"@types/node": "^22.10.9",
"@types/node": "^22.10.10",
"@types/node-cache": "^4.2.5",
"@types/supertest": "^6.0.2",
"@types/swagger-ui-express": "^4.1.7",
Expand Down
2 changes: 1 addition & 1 deletion modules/private-shared-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"devDependencies": {
"@eslint/compat": "^1.2.5",
"@types/node": "^22.10.9",
"@types/node": "^22.10.10",
"@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^8.21.0",
"@typescript-eslint/parser": "^8.21.0",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
},
"devDependencies": {
"@types/jest": "^29.5.14",
"@types/node": "^22.10.9",
"@types/node": "^22.10.10",
"@types/node-cache": "^4.2.5",
"@typescript-eslint/eslint-plugin": "^8.21.0",
"@typescript-eslint/parser": "^8.21.0",
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2695,7 +2695,7 @@ __metadata:
"@types/convict": ^6.1.6
"@types/express": ^5.0.0
"@types/jest": ^29.5.14
"@types/node": ^22.10.9
"@types/node": ^22.10.10
"@types/node-cache": ^4.2.5
"@types/supertest": ^6.0.2
"@types/swagger-ui-express": 4.1.7
Expand Down Expand Up @@ -2733,7 +2733,7 @@ __metadata:
"@types/convict": ^6.1.6
"@types/express": ^5.0.0
"@types/jest": ^29.5.14
"@types/node": ^22.10.9
"@types/node": ^22.10.10
"@types/node-cache": ^4.2.5
"@types/supertest": ^6.0.2
"@types/swagger-ui-express": ^4.1.7
Expand Down Expand Up @@ -2769,7 +2769,7 @@ __metadata:
"@mojaloop/logging-bc-public-types-lib": ^0.5.4
"@mojaloop/platform-shared-lib-messaging-types-lib": ^0.7.1
"@mojaloop/platform-shared-lib-nodejs-kafka-client-lib": 0.5.18
"@types/node": ^22.10.9
"@types/node": ^22.10.10
"@types/uuid": ^10.0.0
"@typescript-eslint/eslint-plugin": ^8.21.0
"@typescript-eslint/parser": ^8.21.0
Expand All @@ -2792,7 +2792,7 @@ __metadata:
resolution: "@mojaloop/sdk-scheme-adapter@workspace:."
dependencies:
"@types/jest": ^29.5.14
"@types/node": ^22.10.9
"@types/node": ^22.10.10
"@types/node-cache": ^4.2.5
"@typescript-eslint/eslint-plugin": ^8.21.0
"@typescript-eslint/parser": ^8.21.0
Expand Down Expand Up @@ -3843,12 +3843,12 @@ __metadata:
languageName: node
linkType: hard

"@types/node@npm:^22.10.9":
version: 22.10.9
resolution: "@types/node@npm:22.10.9"
"@types/node@npm:^22.10.10":
version: 22.10.10
resolution: "@types/node@npm:22.10.10"
dependencies:
undici-types: ~6.20.0
checksum: bd9a94fe5de516dcf13b4e9268696a99be3ba7146322c92b5ca3ea5368846cbb851843e2dda7030636653738405ea67e7bd972c630733420f84e199ad2c440ec
checksum: 4906f63dd1dcee6acc096b3336353e04a15746b639bbf4f585e3093851a17852a9ea0e302caef2d782c836adb3812e6eb3305b8783809320013a1d77798816b3
languageName: node
linkType: hard

Expand Down

0 comments on commit 19c43b1

Please sign in to comment.