From c9507b7e4c396706e966c05446096af5a164c250 Mon Sep 17 00:00:00 2001 From: Alena Khineika Date: Thu, 27 Feb 2025 16:16:53 +0100 Subject: [PATCH] fix(build): github api calls for homebrew release fail MONGOSH-1928 (#2387) * fix(build): github api calls for homebrew release fail MONGOSH-1928 * docs: add a comment * refactor: rename function and add console error --- .../build/src/homebrew/generate-formula.ts | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/packages/build/src/homebrew/generate-formula.ts b/packages/build/src/homebrew/generate-formula.ts index 7671dd116..4b416c245 100644 --- a/packages/build/src/homebrew/generate-formula.ts +++ b/packages/build/src/homebrew/generate-formula.ts @@ -1,15 +1,37 @@ import * as semver from 'semver'; import type { GithubRepo } from '@mongodb-js/devtools-github-repo'; +/** + * When sending requests via Octokit, a situation can arise where the server closes the connection, + * but the client still believes it’s open and attempts to write to it, + * what leads to receiving an EPIPE error from the OS, indicating the connection has already been closed. + * In such cases, retrying the request can help establish a new, functional connection. + */ +async function getFormulaFromRepositoryWithRetry( + homebrewCore: GithubRepo, + remainingRetries = 3 +) { + try { + return await homebrewCore.getFileContent('Formula/m/mongosh.rb', 'master'); + } catch (error: any) { + if (error.message.includes('EPIPE') && remainingRetries > 0) { + console.error(error); + return await getFormulaFromRepositoryWithRetry( + homebrewCore, + remainingRetries - 1 + ); + } else { + throw error; + } + } +} + export async function generateUpdatedFormula( context: { version: string; sha: string }, homebrewCore: GithubRepo, isDryRun: boolean ): Promise { - const currentFormula = await homebrewCore.getFileContent( - 'Formula/m/mongosh.rb', - 'master' - ); + const currentFormula = await getFormulaFromRepositoryWithRetry(homebrewCore); const urlMatch = /url "([^"]+)"/g.exec(currentFormula.content); const shaMatch = /sha256 "([^"]+)"/g.exec(currentFormula.content);