diff --git a/tdrive/backend/node/package-lock.json b/tdrive/backend/node/package-lock.json index 02f6ad54..51f6c235 100644 --- a/tdrive/backend/node/package-lock.json +++ b/tdrive/backend/node/package-lock.json @@ -103,7 +103,7 @@ "@types/html-to-text": "^8.1.1", "@types/jest": "^29.5.12", "@types/lodash": "^4.14.165", - "@types/node": "^18.11", + "@types/node": "^20.17.16", "@types/node-cron": "^3.0.0", "@types/node-fetch": "^2.5.12", "@types/node-uuid": "^0.0.28", @@ -2821,11 +2821,11 @@ "dev": true }, "node_modules/@types/node": { - "version": "18.19.31", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.31.tgz", - "integrity": "sha512-ArgCD39YpyyrtFKIqMDvjz79jto5fcI/SVUs2HwB+f0dAzq68yqOdyaSivLiLugSziTpNXLQrVb7RZFmdZzbhA==", + "version": "20.17.16", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.17.16.tgz", + "integrity": "sha512-vOTpLduLkZXePLxHiHsBLp98mHGnl8RptV4YAO3HfKO5UHjDvySGbxKtpYfy8Sx5+WKcgc45qNreJJRVM3L6mw==", "dependencies": { - "undici-types": "~5.26.4" + "undici-types": "~6.19.2" } }, "node_modules/@types/node-cron": { @@ -12492,9 +12492,9 @@ "dev": true }, "node_modules/undici-types": { - "version": "5.26.5", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==" + "version": "6.19.8", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", + "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==" }, "node_modules/universalify": { "version": "2.0.1", diff --git a/tdrive/backend/node/package.json b/tdrive/backend/node/package.json index 6bc3eb2b..5b46981f 100644 --- a/tdrive/backend/node/package.json +++ b/tdrive/backend/node/package.json @@ -18,7 +18,7 @@ "lint": "eslint . --ext .ts --quiet --fix", "lint:no-fix": "eslint . --ext .ts", "lint:prettier": "prettier --check --config .prettierrc 'src/**/*.ts'", - "serve": "node --unhandled-rejections=warn --max-http-header-size=30000 dist/server.js", + "serve": "node --unhandled-rejections=warn --max-http-header-size=30000 --expose-gc dist/server.js", "serve:watch": "nodemon dist/server.js | pino-pretty", "serve:debug": "nodemon --inspect dist/server.js | pino-pretty", "start": "npm run serve", @@ -70,7 +70,7 @@ "@types/html-to-text": "^8.1.1", "@types/jest": "^29.5.12", "@types/lodash": "^4.14.165", - "@types/node": "^18.11", + "@types/node": "^20.17.16", "@types/node-cron": "^3.0.0", "@types/node-fetch": "^2.5.12", "@types/node-uuid": "^0.0.28", diff --git a/tdrive/backend/node/src/core/platform/services/diagnostics/utils.ts b/tdrive/backend/node/src/core/platform/services/diagnostics/utils.ts index 375a1ebe..c78a9873 100644 --- a/tdrive/backend/node/src/core/platform/services/diagnostics/utils.ts +++ b/tdrive/backend/node/src/core/platform/services/diagnostics/utils.ts @@ -1,6 +1,6 @@ import { logger } from "../../framework"; import { Readable, Transform } from "node:stream"; -import { Session } from "node:inspector"; +import { Session } from "node:inspector/promises"; /** Time the execution of the callback, and return its duration in ms with the result */ export async function timeCallback( @@ -15,7 +15,7 @@ export async function timeCallback( * synchroneously (because of session.post) pipe it to a stream * readable from the first argument of the callback. */ -export function getHeapSnapshotSync(cb: (readable: Readable) => void) { +export async function getHeapSnapshotSync(cb: (readable: Readable) => void) { logger.info({ gcExposed: !!global.gc }, "Beginning heap snapshot"); if (global.gc) global.gc(); const session = new Session(); @@ -24,12 +24,13 @@ export function getHeapSnapshotSync(cb: (readable: Readable) => void) { const transform = new Transform(); try { let size = 0; + await session.post("HeapProfiler.enable"); session.on("HeapProfiler.addHeapSnapshotChunk", message => { size += message.params.chunk.length; transform.push(message.params.chunk); }); cb(transform); - session.post("HeapProfiler.takeHeapSnapshot", null); + await session.post("HeapProfiler.takeHeapSnapshot", null); logger.info({ size }, "Heap snapshot sent"); } finally { transform.end(); diff --git a/tdrive/backend/node/src/core/platform/services/diagnostics/web/heap-routes.ts b/tdrive/backend/node/src/core/platform/services/diagnostics/web/heap-routes.ts index eb294cf8..093b14e9 100644 --- a/tdrive/backend/node/src/core/platform/services/diagnostics/web/heap-routes.ts +++ b/tdrive/backend/node/src/core/platform/services/diagnostics/web/heap-routes.ts @@ -17,7 +17,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, _opts, next) => `attachment; filename="twake-drive-snap-${filenameTimestamp}.heapsnapshot"`, ); let replyResult; - getHeapSnapshotSync(readable => (replyResult = reply.send(readable))); + await getHeapSnapshotSync(readable => (replyResult = reply.send(readable))); return replyResult; }); } diff --git a/tdrive/backend/node/src/services/previews/services/files/engine/service.ts b/tdrive/backend/node/src/services/previews/services/files/engine/service.ts index 46f85930..79760690 100644 --- a/tdrive/backend/node/src/services/previews/services/files/engine/service.ts +++ b/tdrive/backend/node/src/services/previews/services/files/engine/service.ts @@ -71,7 +71,7 @@ export class PreviewProcessor readable.pipe(writable); - await new Promise(r => { + await new Promise(r => { writable.on("finish", r); }); diff --git a/tdrive/backend/node/src/utils/files.ts b/tdrive/backend/node/src/utils/files.ts index f4c9c337..47bae4a0 100644 --- a/tdrive/backend/node/src/utils/files.ts +++ b/tdrive/backend/node/src/utils/files.ts @@ -43,7 +43,7 @@ export const writeToTemporaryFile = async (input: Readable, extension: string): input.pipe(writable); - await new Promise(r => { + await new Promise(r => { writable.on("finish", r); }); diff --git a/tdrive/backend/node/test/http/diagnostic.http b/tdrive/backend/node/test/http/diagnostic.http new file mode 100644 index 00000000..f06c5629 --- /dev/null +++ b/tdrive/backend/node/test/http/diagnostic.http @@ -0,0 +1,6 @@ +POST http://localhost:4000/diagnostics/heap?secret=diag-secret +Authorization: Basic admin admin +Content-Type: application/json + +{ +} \ No newline at end of file diff --git a/tdrive/backend/node/yarn.lock b/tdrive/backend/node/yarn.lock index 877f208b..c985948f 100644 --- a/tdrive/backend/node/yarn.lock +++ b/tdrive/backend/node/yarn.lock @@ -493,6 +493,11 @@ rfdc "^1.3.0" yaml "^2.2.2" +"@ffprobe-installer/darwin-arm64@5.0.1": + version "5.0.1" + resolved "https://registry.npmjs.org/@ffprobe-installer/darwin-arm64/-/darwin-arm64-5.0.1.tgz" + integrity sha512-vwNCNjokH8hfkbl6m95zICHwkSzhEvDC3GVBcUp5HX8+4wsX10SP3B+bGur7XUzTIZ4cQpgJmEIAx6TUwRepMg== + "@ffprobe-installer/ffprobe@^1.4.1": version "1.4.1" resolved "https://registry.npmjs.org/@ffprobe-installer/ffprobe/-/ffprobe-1.4.1.tgz" @@ -507,11 +512,6 @@ "@ffprobe-installer/win32-ia32" "5.0.0" "@ffprobe-installer/win32-x64" "5.0.0" -"@ffprobe-installer/linux-x64@5.0.0": - version "5.0.0" - resolved "https://registry.npmjs.org/@ffprobe-installer/linux-x64/-/linux-x64-5.0.0.tgz" - integrity sha512-zgLnWJFvMGCaw1txGtz84sMEQt6mQUzdw86ih9S/kZOWnp06Gj/ams/EXxEkAxgAACCVM6/O0mkDe/6biY5tgA== - "@humanwhocodes/config-array@^0.11.14": version "0.11.14" resolved "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.14.tgz" @@ -531,29 +531,17 @@ resolved "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.3.tgz" integrity sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA== -"@img/sharp-libvips-linux-x64@1.0.2": - version "1.0.2" - resolved "https://registry.npmjs.org/@img/sharp-libvips-linux-x64/-/sharp-libvips-linux-x64-1.0.2.tgz" - integrity sha512-E441q4Qdb+7yuyiADVi5J+44x8ctlrqn8XgkDTwr4qPJzWkaHwD489iZ4nGDgcuya4iMN3ULV6NwbhRZJ9Z7SQ== - -"@img/sharp-libvips-linuxmusl-x64@1.0.2": - version "1.0.2" - resolved "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-x64/-/sharp-libvips-linuxmusl-x64-1.0.2.tgz" - integrity sha512-VI94Q6khIHqHWNOh6LLdm9s2Ry4zdjWJwH56WoiJU7NTeDwyApdZZ8c+SADC8OH98KWNQXnE01UdJ9CSfZvwZw== - -"@img/sharp-linux-x64@0.33.3": +"@img/sharp-darwin-arm64@0.33.3": version "0.33.3" - resolved "https://registry.npmjs.org/@img/sharp-linux-x64/-/sharp-linux-x64-0.33.3.tgz" - integrity sha512-Q4I++herIJxJi+qmbySd072oDPRkCg/SClLEIDh5IL9h1zjhqjv82H0Seupd+q2m0yOfD+/fJnjSoDFtKiHu2g== + resolved "https://registry.npmjs.org/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.33.3.tgz" + integrity sha512-FaNiGX1MrOuJ3hxuNzWgsT/mg5OHG/Izh59WW2mk1UwYHUwtfbhk5QNKYZgxf0pLOhx9ctGiGa2OykD71vOnSw== optionalDependencies: - "@img/sharp-libvips-linux-x64" "1.0.2" + "@img/sharp-libvips-darwin-arm64" "1.0.2" -"@img/sharp-linuxmusl-x64@0.33.3": - version "0.33.3" - resolved "https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.33.3.tgz" - integrity sha512-Jhchim8kHWIU/GZ+9poHMWRcefeaxFIs9EBqf9KtcC14Ojk6qua7ghKiPs0sbeLbLj/2IGBtDcxHyjCdYWkk2w== - optionalDependencies: - "@img/sharp-libvips-linuxmusl-x64" "1.0.2" +"@img/sharp-libvips-darwin-arm64@1.0.2": + version "1.0.2" + resolved "https://registry.npmjs.org/@img/sharp-libvips-darwin-arm64/-/sharp-libvips-darwin-arm64-1.0.2.tgz" + integrity sha512-tcK/41Rq8IKlSaKRCCAuuY3lDJjQnYIW1UXU1kxcEKrfL8WR7N6+rzNoOxoQRJWTAECuKwgAHnPvqXGN8XfkHA== "@isaacs/cliui@^8.0.2": version "8.0.2" @@ -1366,12 +1354,12 @@ dependencies: "@types/node" "*" -"@types/node@*", "@types/node@^18.11", "@types/node@>=10.0.0": - version "18.19.31" - resolved "https://registry.npmjs.org/@types/node/-/node-18.19.31.tgz" - integrity sha512-ArgCD39YpyyrtFKIqMDvjz79jto5fcI/SVUs2HwB+f0dAzq68yqOdyaSivLiLugSziTpNXLQrVb7RZFmdZzbhA== +"@types/node@*", "@types/node@^20.17.16", "@types/node@>=10.0.0": + version "20.17.16" + resolved "https://registry.npmjs.org/@types/node/-/node-20.17.16.tgz" + integrity sha512-vOTpLduLkZXePLxHiHsBLp98mHGnl8RptV4YAO3HfKO5UHjDvySGbxKtpYfy8Sx5+WKcgc45qNreJJRVM3L6mw== dependencies: - undici-types "~5.26.4" + undici-types "~6.19.2" "@types/node@^15.0.1": version "15.14.9" @@ -3605,6 +3593,11 @@ fs.realpath@^1.0.0: resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== +fsevents@^2.3.2, fsevents@~2.3.2: + version "2.3.3" + resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz" + integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw== + fstream@^1.0.12: version "1.0.12" resolved "https://registry.npmjs.org/fstream/-/fstream-1.0.12.tgz" @@ -7345,10 +7338,10 @@ undefsafe@^2.0.5: resolved "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz" integrity sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA== -undici-types@~5.26.4: - version "5.26.5" - resolved "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz" - integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== +undici-types@~6.19.2: + version "6.19.8" + resolved "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz" + integrity sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw== universalify@^2.0.0: version "2.0.1" diff --git a/tdrive/docker-compose.minimal.yml b/tdrive/docker-compose.minimal.yml index ed303282..7edcc3ca 100644 --- a/tdrive/docker-compose.minimal.yml +++ b/tdrive/docker-compose.minimal.yml @@ -6,11 +6,10 @@ services: image: mongo healthcheck: test: echo 'db.runCommand("ping").ok' | mongosh localhost:27017/test --quiet - interval: 2m + interval: 10s timeout: 2m retries: 30 start_period: 10s - start_interval: 3s volumes: - ./docker-data/mongo:/data/db ports: