Skip to content

Commit 538ce3e

Browse files
authored
fix(internal/librarian/nodejs): isolate owl-bot-staging cleanups to package subdirectories (#5965)
When running `librarian generate --all` or concurrent generations in parallel async threads, the Go engine's Node.js post-processor executed a sweeping `os.RemoveAll` cleanup on the shared top-level `owl-bot- staging/` folder. This pulled the directory out from underneath other active parallel compilation processes, leading to random `No such file or directory` crashes. This patch isolates the post-processor cleanup to package-specific subdirectories (`owl-bot-staging/<package_name>`), eliminating the parallel staging deletion race condition. Closes #5957
1 parent ef0866e commit 538ce3e

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

internal/librarian/nodejs/generate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,8 @@ func runPostProcessor(ctx context.Context, cfg *config.Config, library *config.L
365365
}
366366
}
367367

368-
if err := os.RemoveAll(filepath.Join(repoRoot, "owl-bot-staging")); err != nil && !errors.Is(err, fs.ErrNotExist) {
369-
return fmt.Errorf("failed to remove owl-bot-staging: %w", err)
368+
if err := os.RemoveAll(stagingDir); err != nil && !errors.Is(err, fs.ErrNotExist) {
369+
return fmt.Errorf("failed to remove package staging: %w", err)
370370
}
371371
return nil
372372
}

internal/librarian/nodejs/generate_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,13 @@ func TestRunPostProcessor(t *testing.T) {
445445
if err := runPostProcessor(t.Context(), cfg, library, "", repoRoot, outDir); err != nil {
446446
t.Fatal(err)
447447
}
448-
if _, err := os.Stat(filepath.Join(repoRoot, "owl-bot-staging")); !errors.Is(err, fs.ErrNotExist) {
449-
t.Error("expected owl-bot-staging to be removed after post-processing")
448+
// Verify that the package staging directory is successfully cleaned up
449+
if _, err := os.Stat(filepath.Join(repoRoot, "owl-bot-staging", library.Name)); !errors.Is(err, fs.ErrNotExist) {
450+
t.Error("expected package staging directory to be removed after post-processing")
451+
}
452+
// Verify that the top-level owl-bot-staging parent folder itself remains intact to support parallel executions
453+
if _, err := os.Stat(filepath.Join(repoRoot, "owl-bot-staging")); err != nil {
454+
t.Error("expected top-level owl-bot-staging directory to remain intact")
450455
}
451456
}
452457

@@ -549,8 +554,13 @@ func TestRunPostProcessor_CustomScripts(t *testing.T) {
549554
if err := runPostProcessor(t.Context(), cfg, library, "", repoRoot, outDir); err != nil {
550555
t.Fatal(err)
551556
}
552-
if _, err := os.Stat(filepath.Join(repoRoot, "owl-bot-staging")); !errors.Is(err, fs.ErrNotExist) {
553-
t.Error("expected owl-bot-staging to be removed after post-processing")
557+
// Verify package staging directory is cleaned up
558+
if _, err := os.Stat(filepath.Join(repoRoot, "owl-bot-staging", library.Name)); !errors.Is(err, fs.ErrNotExist) {
559+
t.Error("expected package staging directory to be removed after post-processing")
560+
}
561+
// Verify parent folder remains intact
562+
if _, err := os.Stat(filepath.Join(repoRoot, "owl-bot-staging")); err != nil {
563+
t.Error("expected top-level owl-bot-staging directory to remain intact")
554564
}
555565

556566
if _, err := os.Stat(filepath.Join(repoRoot, "librarian-ran.txt")); err != nil {

0 commit comments

Comments
 (0)