Copilot commented on code in PR #77306:
URL: https://github.com/apache/airflow/pull/77306#discussion_r4667582031


##########
ts-sdk/src/cli/pack.ts:
##########
@@ -115,24 +125,39 @@ function readSdkVersion(): string {
 }
 
 function readBundleManifest(bundlePath: string): BundleManifest {
+  // On macOS Node writes a piped stderr asynchronously, so output past the 64 
KiB pipe buffer is
+  // lost when the bundle exits, and Node prints the whole minified line 
before the error.
+  // Writes to a file are synchronous.
+  const stderrDir = mkdtempSync(path.join(tmpdir(), "airflow-ts-pack-"));
+  const stderrPath = path.join(stderrDir, "stderr");
+  const stderrFd = openSync(stderrPath, "w");
   let stdout: string;
   try {
     stdout = execFileSync(process.execPath, [bundlePath, 
AIRFLOW_METADATA_FLAG], {
       encoding: "utf-8",
+      stdio: ["pipe", "pipe", stderrFd],

Review Comment:
   Redirecting stderr to a file bypasses `execFileSync`'s 64 MiB `maxBuffer` 
limit. A noisy bundle can now exhaust temporary storage during the timeout, and 
the full-file reads at lines 143 and 146 can exhaust memory before reporting 
its error. Enforce a stderr size limit during capture and use bounded reads for 
diagnostics and successful log forwarding.



##########
ts-sdk/src/cli/pack.ts:
##########
@@ -115,24 +125,39 @@ function readSdkVersion(): string {
 }
 
 function readBundleManifest(bundlePath: string): BundleManifest {
+  // On macOS Node writes a piped stderr asynchronously, so output past the 64 
KiB pipe buffer is
+  // lost when the bundle exits, and Node prints the whole minified line 
before the error.
+  // Writes to a file are synchronous.
+  const stderrDir = mkdtempSync(path.join(tmpdir(), "airflow-ts-pack-"));
+  const stderrPath = path.join(stderrDir, "stderr");
+  const stderrFd = openSync(stderrPath, "w");
   let stdout: string;
   try {
     stdout = execFileSync(process.execPath, [bundlePath, 
AIRFLOW_METADATA_FLAG], {
       encoding: "utf-8",
+      stdio: ["pipe", "pipe", stderrFd],
       timeout: MANIFEST_TIMEOUT_MS,
       maxBuffer: MANIFEST_MAX_BUFFER_BYTES,
     });
+    // Still pass on what a working bundle logs, such as warnings from user 
code.
+    const logged = readFileSync(stderrPath, "utf-8");
+    if (logged) process.stderr.write(logged);

Review Comment:
   When the CLI's stderr is piped, forwarding large warnings here can leave 
output buffered. If metadata validation then fails, `main.ts:27` immediately 
calls `process.exit(1)`, which can discard both pending warnings and the error 
printed behind them. Set `process.exitCode = 1` instead so stderr can drain, 
and add an executable-path regression test with piped stderr, large warnings, 
and missing metadata.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to