Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: memory leaks #497

Merged
merged 5 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn dep:check
yarn lint
6 changes: 3 additions & 3 deletions modules/api-svc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@
},
"dependencies": {
"@koa/cors": "^5.0.0",
"@mojaloop/api-snippets": "17.5.1",
"@mojaloop/api-snippets": "17.6.1",
"@mojaloop/central-services-error-handling": "^13.0.1",
"@mojaloop/central-services-logger": "^11.5.1",
"@mojaloop/central-services-metrics": "^12.0.8",
"@mojaloop/central-services-shared": "18.7.3",
"@mojaloop/central-services-shared": "18.7.5",
"@mojaloop/event-sdk": "^14.1.1",
"@mojaloop/sdk-scheme-adapter-private-shared-lib": "workspace:^",
"@mojaloop/sdk-standard-components": "18.4.0",
Expand All @@ -76,7 +76,7 @@
"co-body": "^6.2.0",
"dotenv": "^16.4.5",
"env-var": "^7.5.0",
"express": "^4.19.2",
"express": "^4.21.0",
"fast-json-patch": "^3.1.1",
"fast-safe-stringify": "^2.1.1",
"javascript-state-machine": "^3.1.0",
Expand Down
7 changes: 4 additions & 3 deletions modules/api-svc/src/InboundServer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const specPath = path.join(__dirname, 'api.yaml');
const apiSpecs = yaml.load(fs.readFileSync(specPath));

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

class InboundApi extends EventEmitter {
constructor(conf, logger, cache, validator, wso2) {
Expand Down Expand Up @@ -138,13 +140,12 @@ class InboundServer extends EventEmitter {
constructor(conf, logger, cache, wso2) {
super({ captureExceptions: true });
this._conf = conf;
this._validator = new Validate({ logExcludePaths });
this._logger = logger;
this._api = new InboundApi(
conf,
this._logger.push({ component: 'api' }),
cache,
this._validator,
_validator,
wso2,
);
this._api.on('error', (...args) => {
Expand All @@ -159,7 +160,7 @@ class InboundServer extends EventEmitter {

async start() {
assert(!this._server.listening, 'Server already listening');
await this._validator.initialise(apiSpecs);
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
7 changes: 4 additions & 3 deletions modules/api-svc/src/OutboundServer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const apiSpecs = yaml.load(fs.readFileSync(specPath));

const endpointRegex = /\/.*/g;
const logExcludePaths = ['/'];
const _validator = new Validate({ logExcludePaths });
const _initialize = _validator.initialise(apiSpecs);

class OutboundApi extends EventEmitter {
constructor(conf, logger, cache, validator, metricsClient, wso2, eventProducer, eventLogger) {
Expand Down Expand Up @@ -87,7 +89,6 @@ class OutboundApi extends EventEmitter {
class OutboundServer extends EventEmitter {
constructor(conf, logger, cache, metricsClient, wso2) {
super({ captureExceptions: true });
this._validator = new Validate({ logExcludePaths });
this._conf = conf;
this._logger = logger;
this._server = null;
Expand All @@ -100,7 +101,7 @@ class OutboundServer extends EventEmitter {
conf,
this._logger.push({ component: 'api' }),
cache,
this._validator,
_validator,
metricsClient,
wso2,
this._eventProducer,
Expand All @@ -115,7 +116,7 @@ class OutboundServer extends EventEmitter {
async start() {
const { port } = this._conf.outbound;
await this._eventProducer?.init();
await this._validator.initialise(apiSpecs);
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
8 changes: 4 additions & 4 deletions modules/api-svc/src/TestServer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const ws = require('ws');

const http = require('http');
const yaml = require('js-yaml');
const fs = require('fs').promises;
const path = require('path');

const Validate = require('../lib/validate');
Expand All @@ -22,6 +21,8 @@ const handlers = require('./handlers');
const middlewares = require('../InboundServer/middlewares');

const logExcludePaths = ['/'];
const _validator = new Validate({ logExcludePaths });
const _initialize = _validator.initialise(yaml.load(require('fs').readFileSync(path.join(__dirname, 'api.yaml'))));

const getWsIp = (req) => [
req.socket.remoteAddress,
Expand Down Expand Up @@ -176,7 +177,6 @@ class TestServer {
constructor({ port, logger, cache }) {
this._port = port;
this._logger = logger;
this._validator = new Validate({ logExcludePaths });
this._api = new TestApi(this._logger.push({ component: 'api' }), this._validator, cache);
this._server = http.createServer(this._api.callback());
// TODO: why does this appear to need to be called after creating this._server (try reorder
Expand All @@ -188,8 +188,8 @@ class TestServer {
if (this._server.listening) {
return;
}
const fileData = await fs.readFile(path.join(__dirname, 'api.yaml'));
await this._validator.initialise(yaml.load(fileData));

await _initialize;

await this._wsapi.start();

Expand Down
10 changes: 5 additions & 5 deletions modules/outbound-command-event-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@
"snapshot": "standard-version --no-verify --skip.changelog --prerelease snapshot --releaseCommitMessageFormat 'chore(snapshot): {{currentTag}}'"
},
"dependencies": {
"@mojaloop/api-snippets": "17.5.1",
"@mojaloop/central-services-shared": "^18.7.3",
"@mojaloop/api-snippets": "17.6.1",
"@mojaloop/central-services-shared": "^18.7.5",
"@mojaloop/logging-bc-client-lib": "^0.1.17",
"@mojaloop/logging-bc-public-types-lib": "^0.5.4",
"@mojaloop/sdk-scheme-adapter-private-shared-lib": "workspace:^",
"ajv": "^8.17.1",
"convict": "^6.2.4",
"express": "^4.19.2",
"openapi-backend": "^5.10.6",
"express": "^4.21.0",
"openapi-backend": "^5.11.0",
"redis": "^4.7.0",
"swagger-ui-express": "^5.0.1",
"yamljs": "^0.3.0"
Expand All @@ -74,7 +74,7 @@
"standard-version": "^9.5.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.5.4"
"typescript": "^5.6.2"
},
"nodemonConfig": {
"watch": [
Expand Down
8 changes: 4 additions & 4 deletions modules/outbound-domain-event-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
"snapshot": "standard-version --no-verify --skip.changelog --prerelease snapshot --releaseCommitMessageFormat 'chore(snapshot): {{currentTag}}'"
},
"dependencies": {
"@mojaloop/api-snippets": "17.5.1",
"@mojaloop/api-snippets": "17.6.1",
"@mojaloop/logging-bc-client-lib": "^0.1.17",
"@mojaloop/logging-bc-public-types-lib": "^0.5.4",
"@mojaloop/sdk-scheme-adapter-private-shared-lib": "workspace:^",
"convict": "^6.2.4",
"express": "^4.19.2",
"openapi-backend": "^5.10.6",
"express": "^4.21.0",
"openapi-backend": "^5.11.0",
"redis": "^4.7.0",
"swagger-ui-express": "^5.0.1",
"yamljs": "^0.3.0"
Expand All @@ -72,7 +72,7 @@
"standard-version": "^9.5.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.5.4"
"typescript": "^5.6.2"
},
"nodemonConfig": {
"watch": [
Expand Down
8 changes: 4 additions & 4 deletions modules/private-shared-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
"snapshot": "standard-version --no-verify --skip.changelog --prerelease snapshot --releaseCommitMessageFormat 'chore(snapshot): {{currentTag}}'"
},
"dependencies": {
"@mojaloop/api-snippets": "17.5.1",
"@mojaloop/central-services-shared": "^18.7.3",
"@mojaloop/api-snippets": "17.6.1",
"@mojaloop/central-services-shared": "^18.7.5",
"@mojaloop/logging-bc-public-types-lib": "^0.5.4",
"@mojaloop/platform-shared-lib-messaging-types-lib": "^0.6.2",
"@mojaloop/platform-shared-lib-messaging-types-lib": "^0.7.1",
"@mojaloop/platform-shared-lib-nodejs-kafka-client-lib": "0.2.15",
"ajv": "^8.17.1",
"redis": "^4.7.0",
Expand All @@ -45,7 +45,7 @@
"replace": "^1.2.2",
"standard-version": "^9.5.0",
"ts-jest": "^29.2.5",
"typescript": "^5.5.4"
"typescript": "^5.6.2"
},
"standard-version": {
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@
"eslint": "^8.57.0",
"eslint-config-airbnb-typescript": "^18.0.0",
"eslint-plugin-import": "latest",
"husky": "^9.1.5",
"husky": "^9.1.6",
"jest": "^29.7.0",
"nodemon": "^3.1.4",
"npm-check-updates": "^16.7.10",
"replace": "^1.2.2",
"standard-version": "^9.5.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.5.4",
"typescript": "^5.6.2",
"yarn-audit-fix": "^10.0.9"
},
"resolutions": {
Expand Down
Loading