From 52c6c3b0ea2d0c613e14b39ec07ad43db19cf3ba Mon Sep 17 00:00:00 2001 From: mappu Date: Wed, 11 Sep 2024 17:44:36 +1200 Subject: [PATCH] genbindings: add retry logic to clang subprocess execution --- cmd/genbindings/main.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/cmd/genbindings/main.go b/cmd/genbindings/main.go index c35f9fb3..e6b87bc0 100644 --- a/cmd/genbindings/main.go +++ b/cmd/genbindings/main.go @@ -9,6 +9,7 @@ import ( "os" "path/filepath" "strings" + "time" ) func cacheFilePath(inputHeader string) string { @@ -96,9 +97,22 @@ func main() { log.Printf("No AST cache for file %q, running clang...", filepath.Base(inputHeader)) // Parse the file - astInner, err = clangExec(ctx, *clang, inputHeader, strings.Fields(*cflags)) + // This seems to intermittently fail, so allow retrying + nextRetry: + for retryCt := 0; retryCt < 5; retryCt++ { + astInner, err = clangExec(ctx, *clang, inputHeader, strings.Fields(*cflags)) + if err != nil { + // Log and continue with next retry + log.Printf("WARNING: Clang execution failed: %v", err) + time.Sleep(3 * time.Second) + log.Printf("Retrying...") + + } else { // err == nil + break nextRetry + } + } if err != nil { - panic(err) + panic("Clang execution failed after 5x retries") } // Write to cache