Skip to content

Commit

Permalink
fix: memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
awlayton committed Mar 28, 2023
1 parent 92fc352 commit 1a088f7
Show file tree
Hide file tree
Showing 29 changed files with 198 additions and 179 deletions.
4 changes: 2 additions & 2 deletions oada/libs/lib-arangodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@
"@types/deep-equal": "^1.0.1",
"@types/flat": "^5.0.2",
"@types/json-pointer": "^1.0.31",
"@types/node": "^18.15.5",
"@types/node": "^18.15.10",
"ava": "5.2.0",
"type-fest": "^3.6.1"
"type-fest": "^3.7.1"
},
"volta": {
"node": "18.13.0"
Expand Down
2 changes: 1 addition & 1 deletion oada/libs/lib-kafka/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@ava/typescript": "^4.0.0",
"@types/convict": "^6.1.1",
"@types/debug": "^4.1.7",
"@types/node": "^18.15.5",
"@types/node": "^18.15.10",
"@types/uuid": "^9.0.1",
"ava": "5.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion oada/libs/lib-prom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"devDependencies": {
"@ava/typescript": "^4.0.0",
"@types/convict": "^6.1.1",
"@types/node": "^18.15.5",
"@types/node": "^18.15.10",
"@types/ws": "^8.5.4",
"ava": "5.2.0",
"fastify-plugin": "^4.5.0"
Expand Down
2 changes: 1 addition & 1 deletion oada/libs/pino-debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"devDependencies": {
"@types/debug": "^4.1.7",
"@types/node": "^18.15.5"
"@types/node": "^18.15.10"
},
"peerDependencies": {
"debug": "*"
Expand Down
11 changes: 7 additions & 4 deletions oada/libs/pino-debug/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ import { resolve } from 'node:path';
// !!! This needs to be imported before _anything_ using pino or debug
import pinoDebug from 'pino-debug';

import type { Logger, LoggerOptions } from 'pino';
import _pino from 'pino';
import _pino, {
type ChildLoggerOptions,
type Logger,
type LoggerOptions,
} from 'pino';
import debug from 'debug';
import isInteractive from 'is-interactive';
import pinoCaller from 'pino-caller';
Expand Down Expand Up @@ -153,6 +156,6 @@ function createRootLogger(): Logger {
}

const rootLogger = createRootLogger();
export function pino(options: LoggerOptions = {}): Logger {
return rootLogger.child(options);
export function pino(options?: LoggerOptions) {
return rootLogger.child({}, options as ChildLoggerOptions);
}
14 changes: 7 additions & 7 deletions oada/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
"g:pino-pretty": "pino-pretty"
},
"devDependencies": {
"@commitlint/cli": "^17.5.0",
"@commitlint/cli": "^17.5.1",
"@commitlint/config-conventional": "^17.4.4",
"@tsconfig/node18": "^1.0.1",
"@types/eslint": "^8.21.3",
"@types/mocha": "^10.0.1",
"@types/node": "^18.15.5",
"@typescript-eslint/eslint-plugin": "^5.56.0",
"@typescript-eslint/parser": "^5.56.0",
"@yarnpkg/sdks": "^3.0.0-rc.40",
"@types/node": "^18.15.10",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.57.0",
"@yarnpkg/sdks": "^3.0.0-rc.41",
"c8": "^7.13.0",
"eslint": "^8.36.0",
"eslint-config-prettier": "^8.8.0",
Expand All @@ -34,7 +34,7 @@
"eslint-plugin-escompat": "^3.4.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-filenames": "^1.3.2",
"eslint-plugin-github": "^4.6.1",
"eslint-plugin-github": "^4.7.0",
"eslint-plugin-i18n-text": "^1.0.1",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-no-constructor-bind": "^2.0.4",
Expand All @@ -50,7 +50,7 @@
"eslint-plugin-sonarjs": "^0.19.0",
"eslint-plugin-unicorn": "^46.0.0",
"get-port": "^6.1.2",
"prettier": "^2.8.6",
"prettier": "^2.8.7",
"typescript": "5.0.2",
"zx": "^7.2.1"
},
Expand Down
4 changes: 2 additions & 2 deletions oada/services/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"test-arango": "isTest=true mocha test/arango/index.js",
"lint": "jshint --reporter node_modules/jshint-stylish .",
"clean": "rm -rf test/oada-compliance && rm -rf coverage && yarn run build --clean",
"start": "node ${INSPECT} -r @oada/pino-debug --unhandled-rejections=strict dist/index.js",
"start": "node ${INSPECT} --unhandled-rejections=strict dist/index.js",
"init": "node dist/init.js"
},
"mocha": {
Expand Down Expand Up @@ -105,7 +105,7 @@
"@types/urijs": "^1.19.19",
"@types/uuid": "^9.0.1",
"c8": "^7.13.0",
"type-fest": "^3.6.1"
"type-fest": "^3.7.1"
},
"volta": {
"node": "18.13.0"
Expand Down
2 changes: 2 additions & 0 deletions oada/services/auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

import '@oada/pino-debug';

import { config, domainConfigs } from './config.js';

import '@oada/lib-prom';
Expand Down
6 changes: 3 additions & 3 deletions oada/services/http-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"build": "yarn g:tsc",
"clean": "yarn run build --clean",
"healthcheck": "node --enable-source-maps dist/healthcheck.js http://localhost:${PORT}/health",
"start": "node ${INSPECT} --enable-source-maps -r @oada/pino-debug --unhandled-rejections=strict dist/server.js"
"start": "node ${INSPECT} --enable-source-maps --unhandled-rejections=strict dist/server.js"
},
"mocha": {
"require": [
Expand All @@ -42,7 +42,7 @@
"@fastify/helmet": "^10.1.0",
"@fastify/request-context": "^4.2.0",
"@fastify/sensible": "^5.2.0",
"@fastify/websocket": "^7.1.3",
"@fastify/websocket": "^7.2.0",
"@oada/error": "^2.0.1",
"@oada/formats-server": "^3.4.3",
"@oada/lib-arangodb": "^3.7.0",
Expand Down Expand Up @@ -71,7 +71,7 @@
"@oada/write-handler": "^3.7.0",
"@types/cacache": "^15.0.1",
"@types/debug": "^4.1.7",
"@types/node": "^18.15.5",
"@types/node": "^18.15.10",
"@types/type-is": "^1.6.3",
"@types/uuid": "^9.0.1",
"@types/ws": "^8.5.4",
Expand Down
13 changes: 6 additions & 7 deletions oada/services/http-handler/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { fastify as Fastify } from 'fastify';
import bearerAuth from '@fastify/bearer-auth';
import cors from '@fastify/cors';
import fastifyAccepts from '@fastify/accepts';
import { fastifyGracefulShutdown } from 'fastify-graceful-shutdown';
import fastifyGracefulShutdown from 'fastify-graceful-shutdown';
import fastifyHealthcheck from 'fastify-healthcheck';
import fastifySensible from '@fastify/sensible';
import helmet from '@fastify/helmet';
Expand All @@ -59,7 +59,6 @@ export enum EnsureLink {
}

// Set up logging stuff
const logger = pino();
const serializers = {
// Customize logging for requests
req(request: FastifyRequest) {
Expand All @@ -84,6 +83,9 @@ const serializers = {
};
},
};
const logger = pino({ serializers });
// HACK: fastify overrides existing serializers. This circumvents that...
// logger.serializers = serializers;

mixins.push(() => ({
reqId: requestContext.get('id'),
Expand All @@ -93,11 +95,7 @@ const trustProxy = config.get('trustProxy');
// eslint-disable-next-line new-cap
export const fastify = Fastify({
trustProxy,
logger: {
...logger,
// HACK: fastify overrides existing serializers. This circumvents that...
serializers,
},
logger,
ignoreTrailingSlash: true,
constraints: {
oadaEnsureLink: {
Expand Down Expand Up @@ -181,6 +179,7 @@ await fastify.register(fastifySensible);

await fastify.register(fastifyAccepts);

// @ts-expect-error broken types
await fastify.register(fastifyGracefulShutdown);

/**
Expand Down
1 change: 0 additions & 1 deletion oada/services/http-handler/src/websockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ function parseRequest(data: WebSocket.Data): SocketRequest {
}

const plugin: FastifyPluginAsync = async (fastify) => {
// @ts-expect-error IDEK
await fastify.register(fastifyWebsocket);

fastify.get('/*', { websocket: true }, ({ socket }) => {
Expand Down
4 changes: 2 additions & 2 deletions oada/services/permissions-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"scripts": {
"build": "yarn g:tsc",
"clean": "yarn run build --clean",
"start": "node ${INSPECT} --enable-source-maps -r @oada/pino-debug --unhandled-rejections=strict dist/server.js",
"start": "node ${INSPECT} --enable-source-maps --unhandled-rejections=strict dist/server.js",
"test": "mocha"
},
"mocha": {
Expand All @@ -37,7 +37,7 @@
},
"devDependencies": {
"@types/debug": "^4.1.7",
"@types/node": "^18.15.5",
"@types/node": "^18.15.10",
"@types/type-is": "^1.6.3"
},
"volta": {
Expand Down
2 changes: 2 additions & 0 deletions oada/services/permissions-handler/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

import '@oada/pino-debug';

import { config } from './config.js';

import '@oada/lib-prom';
Expand Down
6 changes: 3 additions & 3 deletions oada/services/rev-graph-update/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"test": "yarn run build test && ava",
"build": "yarn g:tsc",
"clean": "yarn run build --clean",
"start": "node ${INSPECT} --enable-source-maps -r @oada/pino-debug --unhandled-rejections=strict dist/index.js"
"start": "node ${INSPECT} --enable-source-maps --unhandled-rejections=strict dist/index.js"
},
"ava": {
"files": [
Expand Down Expand Up @@ -51,10 +51,10 @@
"@oada/client": "^4.5.0",
"@oada/write-handler": "^3.7.0",
"@types/debug": "^4.1.7",
"@types/node": "^18.15.5",
"@types/node": "^18.15.10",
"@types/randomstring": "^1.1.8",
"ava": "5.2.0",
"type-fest": "^3.6.1"
"type-fest": "^3.7.1"
},
"volta": {
"node": "18.13.0"
Expand Down
2 changes: 2 additions & 0 deletions oada/services/rev-graph-update/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

import '@oada/pino-debug';

import { config } from './config.js';

import '@oada/lib-prom';
Expand Down
2 changes: 1 addition & 1 deletion oada/services/shares/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"scripts": {
"build": "yarn g:tsc",
"clean": "yarn run build --clean",
"start": "node ${INSPECT} -r @oada/pino-debug --enable-source-maps --unhandled-rejections=strict dist/server.js",
"start": "node ${INSPECT} --enable-source-maps --unhandled-rejections=strict dist/server.js",
"test": "mocha"
},
"mocha": {
Expand Down
2 changes: 2 additions & 0 deletions oada/services/shares/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

import '@oada/pino-debug';

import { config } from './config.js';

import '@oada/lib-prom';
Expand Down
4 changes: 2 additions & 2 deletions oada/services/startup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"scripts": {
"build": "yarn g:tsc",
"clean": "yarn run build --clean",
"start": "node ${INSPECT} -r @oada/pino-debug --enable-source-maps --unhandled-rejections=strict dist/index.js",
"start": "node ${INSPECT} --enable-source-maps --unhandled-rejections=strict dist/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
Expand All @@ -41,7 +41,7 @@
},
"devDependencies": {
"@types/debug": "^4.1.7",
"@types/node": "^18.15.5"
"@types/node": "^18.15.10"
},
"volta": {
"node": "18.13.0"
Expand Down
2 changes: 2 additions & 0 deletions oada/services/startup/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

import '@oada/pino-debug';

import http from 'node:http';

import { init as initArangoDB } from '@oada/lib-arangodb';
Expand Down
4 changes: 2 additions & 2 deletions oada/services/sync-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"scripts": {
"build": "yarn g:tsc",
"clean": "yarn run build --clean",
"start": "node ${INSPECT} --enable-source-maps -r @oada/pino-debug --unhandled-rejections=strict dist/server.js",
"start": "node ${INSPECT} --enable-source-maps --unhandled-rejections=strict dist/server.js",
"test": "mocha"
},
"repository": {
Expand All @@ -40,7 +40,7 @@
"devDependencies": {
"@oada/write-handler": "^3.7.0",
"@types/debug": "^4.1.7",
"@types/node": "^18.15.5"
"@types/node": "^18.15.10"
},
"volta": {
"node": "18.13.0"
Expand Down
2 changes: 2 additions & 0 deletions oada/services/sync-handler/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

import '@oada/pino-debug';

import { config } from './config.js';

import '@oada/lib-prom';
Expand Down
2 changes: 1 addition & 1 deletion oada/services/users/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"scripts": {
"build": "yarn g:tsc",
"clean": "yarn run build --clean",
"start": "node ${INSPECT} --enable-source-maps -r @oada/pino-debug --unhandled-rejections=strict dist/server.js"
"start": "node ${INSPECT} --enable-source-maps --unhandled-rejections=strict dist/server.js"
},
"bin": {
"add": "./dist/useradd.js"
Expand Down
2 changes: 2 additions & 0 deletions oada/services/users/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

import '@oada/pino-debug';

import { config } from './config.js';

import '@oada/lib-prom';
Expand Down
2 changes: 1 addition & 1 deletion oada/services/webhooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"scripts": {
"build": "yarn g:tsc",
"clean": "yarn run build --clean",
"start": "node ${INSPECT} -r @oada/pino-debug --enable-source-maps --unhandled-rejections=strict dist/server.js",
"start": "node ${INSPECT} --enable-source-maps --unhandled-rejections=strict dist/server.js",
"test": "mocha"
},
"mocha": {
Expand Down
2 changes: 2 additions & 0 deletions oada/services/webhooks/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

import '@oada/pino-debug';

import { config } from './config.js';

import '@oada/lib-prom';
Expand Down
2 changes: 1 addition & 1 deletion oada/services/well-known/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"scripts": {
"build": "yarn g:tsc",
"clean": "yarn run build --clean",
"start": "node ${INSPECT} --enable-source-maps -r @oada/pino-debug --unhandled-rejections=strict dist/index.js",
"start": "node ${INSPECT} --enable-source-maps --unhandled-rejections=strict dist/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
Expand Down
Loading

0 comments on commit 1a088f7

Please sign in to comment.