Skip to content

Conversation

@mchenani
Copy link

No description provided.

@mchenani mchenani marked this pull request as ready for review February 11, 2026 19:37
@mchenani mchenani requested a review from a team as a code owner February 11, 2026 19:37
@mchenani mchenani marked this pull request as draft February 11, 2026 19:37
Comment on lines +264 to +266
process.on("exit", cleanup);
process.on("SIGINT", cleanup);
process.on("SIGTERM", cleanup);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium

src/process-manager.ts:264 Custom SIGINT/SIGTERM handlers suppress Node.js default termination. Consider calling process.exit() after the cleanup to ensure the process actually terminates.

Suggested change
process.on("exit", cleanup);
process.on("SIGINT", cleanup);
process.on("SIGTERM", cleanup);
process.on("exit", cleanup);
process.on("SIGINT", () => {
cleanup();
process.exit(130);
});
process.on("SIGTERM", () => {
cleanup();
process.exit(143);
});

🚀 Want me to fix this? Reply ex: "fix it for me".

🤖 Prompt for AI
In file npm/gateway/src/process-manager.ts around lines 264-266:

Custom `SIGINT`/`SIGTERM` handlers suppress Node.js default termination. Consider calling `process.exit()` after the cleanup to ensure the process actually terminates.

);
}

function gracefulShutdown(child: ChildProcess): Promise<void> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium

src/process-manager.ts:204 Suggestion: make stop() idempotent (track shutdown state) so repeated calls don’t add timers/listeners, and cancel any pending auto‑restart timer to prevent a restart after stopping.

🚀 Want me to fix this? Reply ex: "fix it for me".

🤖 Prompt for AI
In file npm/gateway/src/process-manager.ts around line 204:

Suggestion: make `stop()` idempotent (track shutdown state) so repeated calls don’t add timers/listeners, and cancel any pending auto‑restart timer to prevent a restart after stopping.

Comment on lines +172 to +176
socket.once("error", () => {
socket.close();
// Port is in use (gateway is listening) — this is what we want
resolve(true);
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium

src/process-manager.ts:172 Calling socket.close() in the error handler throws ERR_SERVER_NOT_RUNNING since the server never started. Consider removing that call.

Suggested change
socket.once("error", () => {
socket.close();
// Port is in use (gateway is listening) — this is what we want
resolve(true);
});
socket.once("error", () => {
// Port is in use (gateway is listening) — this is what we want
resolve(true);
});

🚀 Want me to fix this? Reply ex: "fix it for me".

🤖 Prompt for AI
In file npm/gateway/src/process-manager.ts around lines 172-176:

Calling `socket.close()` in the error handler throws `ERR_SERVER_NOT_RUNNING` since the server never started. Consider removing that call.

node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('${PKG_JSON}', 'utf8'));
pkg.version = '${VERSION}';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Critical

npm/sync-versions.sh:31 Command injection vulnerability: VERSION is interpolated directly into JavaScript strings without escaping. A malicious version like 1.0.0'; exec('cmd'); ' would execute arbitrary code. Consider passing VERSION via an environment variable and reading it with process.env.VERSION instead of string interpolation.

🚀 Want me to fix this? Reply ex: "fix it for me".

🤖 Prompt for AI
In file npm/sync-versions.sh around line 31:

Command injection vulnerability: `VERSION` is interpolated directly into JavaScript strings without escaping. A malicious version like `1.0.0'; exec('cmd'); '` would execute arbitrary code. Consider passing `VERSION` via an environment variable and reading it with `process.env.VERSION` instead of string interpolation.

Comment on lines +30 to +31
const earlyExitPromise = new Promise<never>((_, reject) => {
child.on("exit", (code, signal) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High

src/process-manager.ts:30 Missing error event handler on spawned child process. If the binary fails to spawn (permissions, invalid path), Node.js crashes. Consider adding child.on('error', ...) and rejecting earlyExitPromise from it.

-  const earlyExitPromise = new Promise<never>((_, reject) => {
-    child.on("exit", (code, signal) => {
+  const earlyExitPromise = new Promise<never>((_, reject) => {
+    child.on("error", (err) => {
+      reject(new Error(`Gateway failed to spawn: ${err.message}`));
+    });
+    child.on("exit", (code, signal) => {

🚀 Want me to fix this? Reply ex: "fix it for me".

🤖 Prompt for AI
In file npm/gateway/src/process-manager.ts around lines 30-31:

Missing `error` event handler on spawned child process. If the binary fails to spawn (permissions, invalid path), Node.js crashes. Consider adding `child.on('error', ...)` and rejecting `earlyExitPromise` from it.


function setupLogForwarding(child: ChildProcess): void {
child.stdout?.on("data", (data: Buffer) => {
const lines = data.toString().split("\n").filter(Boolean);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Low

src/process-manager.ts:109 Stream data events can split lines across chunks, causing JSON.parse to fail on partial JSON. Consider buffering incomplete lines between chunks and only processing complete lines (those ending with a newline).

🚀 Want me to fix this? Reply ex: "fix it for me".

🤖 Prompt for AI
In file npm/gateway/src/process-manager.ts around line 109:

Stream `data` events can split lines across chunks, causing `JSON.parse` to fail on partial JSON. Consider buffering incomplete lines between chunks and only processing complete lines (those ending with a newline).

Comment on lines +72 to +73
XMTPD_API_PORT: String(port),
XMTPD_API_ENABLE: "true",
Copy link
Collaborator

@mkysel mkysel Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it need the API? Thats a lot of computation for nothing

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now just testing, will clean it up later.


on:
push:
branches: [main, dev]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no dev branch

@mkysel
Copy link
Collaborator

mkysel commented Feb 11, 2026

@mchenani this particular implementation of the gateway does not support any extensions or JWT token auth. Does that meet your requirements?

@mchenani
Copy link
Author

@mchenani this particular implementation of the gateway does not support any extensions or JWT token auth. Does that meet your requirements?

Thanks for the review, tbh I'm not sure if I'm aware of the requirements there, will discuss them with @cameronvoell to make sure I have the full picture how we want to tackle that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants