From 8937703fb75e9f7656e8d324e5cac73cc91db76b Mon Sep 17 00:00:00 2001 From: antoine-coulon Date: Thu, 11 Jan 2024 09:54:54 +0100 Subject: [PATCH 1/4] Avoid defect to be produced when spawned git hash-object fails while computing repo-state --- libraries/package-deps-hash/src/getRepoState.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libraries/package-deps-hash/src/getRepoState.ts b/libraries/package-deps-hash/src/getRepoState.ts index f28e723ce8b..fa8a60ee362 100644 --- a/libraries/package-deps-hash/src/getRepoState.ts +++ b/libraries/package-deps-hash/src/getRepoState.ts @@ -3,7 +3,7 @@ import type * as child_process from 'child_process'; import { once } from 'events'; -import { Readable } from 'stream'; +import { Readable, pipeline } from 'stream'; import { Executable, FileSystem, type IExecutableSpawnOptions } from '@rushstack/node-core-library'; @@ -282,7 +282,13 @@ async function spawnGitAsync( }); if (stdin) { - stdin.pipe(proc.stdin!); + /** + * We are just interested in catching "error" events there from child process' + * proc.stdin to avoid stdin based git commands to throw unhandled exceptions + * hence to let a chance for the error to be thrown in a context we can recover + * from. + */ + pipeline(stdin, proc.stdin!, (err) => {}); } const [status] = await once(proc, 'exit'); From 544884001048684462ebe41d539ae9162ca484bf Mon Sep 17 00:00:00 2001 From: antoine-coulon Date: Thu, 11 Jan 2024 10:01:13 +0100 Subject: [PATCH 2/4] Get rid of devDeps node-core-library from package-deps-hash --- libraries/package-deps-hash/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/package-deps-hash/package.json b/libraries/package-deps-hash/package.json index 0e6f0a6a136..9f5aefaa90b 100644 --- a/libraries/package-deps-hash/package.json +++ b/libraries/package-deps-hash/package.json @@ -17,7 +17,6 @@ }, "devDependencies": { "@rushstack/heft": "workspace:*", - "@rushstack/node-core-library": "workspace:*", "local-node-rig": "workspace:*" }, "dependencies": { From 6f2eb9c280f1f23c83bc158323af1a776cf2b0cd Mon Sep 17 00:00:00 2001 From: antoine-coulon Date: Thu, 11 Jan 2024 10:03:58 +0100 Subject: [PATCH 3/4] Add changes for @rushstack/package-deps-hash --- .../avoid-getrepostate-to-crash_2024-01-11-09-03.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 common/changes/@rushstack/package-deps-hash/avoid-getrepostate-to-crash_2024-01-11-09-03.json diff --git a/common/changes/@rushstack/package-deps-hash/avoid-getrepostate-to-crash_2024-01-11-09-03.json b/common/changes/@rushstack/package-deps-hash/avoid-getrepostate-to-crash_2024-01-11-09-03.json new file mode 100644 index 00000000000..19d28268ba1 --- /dev/null +++ b/common/changes/@rushstack/package-deps-hash/avoid-getrepostate-to-crash_2024-01-11-09-03.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@rushstack/package-deps-hash", + "comment": "Avoid defect to be produced bit spawnGitAsync when the underlying child process stdin stream fails while computing repo-state", + "type": "patch" + } + ], + "packageName": "@rushstack/package-deps-hash" +} \ No newline at end of file From 37f6f99835f9e05af11766abe8d553409faa70ba Mon Sep 17 00:00:00 2001 From: David Michon Date: Wed, 17 Jan 2024 11:19:39 -0800 Subject: [PATCH 4/4] Update wording of comments --- .../avoid-getrepostate-to-crash_2024-01-11-09-03.json | 2 +- libraries/package-deps-hash/src/getRepoState.ts | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/common/changes/@rushstack/package-deps-hash/avoid-getrepostate-to-crash_2024-01-11-09-03.json b/common/changes/@rushstack/package-deps-hash/avoid-getrepostate-to-crash_2024-01-11-09-03.json index 19d28268ba1..8b4b930620c 100644 --- a/common/changes/@rushstack/package-deps-hash/avoid-getrepostate-to-crash_2024-01-11-09-03.json +++ b/common/changes/@rushstack/package-deps-hash/avoid-getrepostate-to-crash_2024-01-11-09-03.json @@ -2,7 +2,7 @@ "changes": [ { "packageName": "@rushstack/package-deps-hash", - "comment": "Avoid defect to be produced bit spawnGitAsync when the underlying child process stdin stream fails while computing repo-state", + "comment": "Handle an edge case in `getRepoState` wherein it tries to asynchronously pipe data to `git hash-object` but the subprocess has already exited.", "type": "patch" } ], diff --git a/libraries/package-deps-hash/src/getRepoState.ts b/libraries/package-deps-hash/src/getRepoState.ts index fa8a60ee362..7af4d11f5e9 100644 --- a/libraries/package-deps-hash/src/getRepoState.ts +++ b/libraries/package-deps-hash/src/getRepoState.ts @@ -283,10 +283,9 @@ async function spawnGitAsync( if (stdin) { /** - * We are just interested in catching "error" events there from child process' - * proc.stdin to avoid stdin based git commands to throw unhandled exceptions - * hence to let a chance for the error to be thrown in a context we can recover - * from. + * For `git hash-object` data is piped in asynchronously. In the event that one of the + * passed filenames cannot be hashed, subsequent writes to `proc.stdin` will error. + * Silence this error since it will be handled by the non-zero exit code of the process. */ pipeline(stdin, proc.stdin!, (err) => {}); }