Skip to content

Commit c9507b7

Browse files
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
1 parent 2377d4a commit c9507b7

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

packages/build/src/homebrew/generate-formula.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
11
import * as semver from 'semver';
22
import type { GithubRepo } from '@mongodb-js/devtools-github-repo';
33

4+
/**
5+
* When sending requests via Octokit, a situation can arise where the server closes the connection,
6+
* but the client still believes it’s open and attempts to write to it,
7+
* what leads to receiving an EPIPE error from the OS, indicating the connection has already been closed.
8+
* In such cases, retrying the request can help establish a new, functional connection.
9+
*/
10+
async function getFormulaFromRepositoryWithRetry(
11+
homebrewCore: GithubRepo,
12+
remainingRetries = 3
13+
) {
14+
try {
15+
return await homebrewCore.getFileContent('Formula/m/mongosh.rb', 'master');
16+
} catch (error: any) {
17+
if (error.message.includes('EPIPE') && remainingRetries > 0) {
18+
console.error(error);
19+
return await getFormulaFromRepositoryWithRetry(
20+
homebrewCore,
21+
remainingRetries - 1
22+
);
23+
} else {
24+
throw error;
25+
}
26+
}
27+
}
28+
429
export async function generateUpdatedFormula(
530
context: { version: string; sha: string },
631
homebrewCore: GithubRepo,
732
isDryRun: boolean
833
): Promise<string | null> {
9-
const currentFormula = await homebrewCore.getFileContent(
10-
'Formula/m/mongosh.rb',
11-
'master'
12-
);
34+
const currentFormula = await getFormulaFromRepositoryWithRetry(homebrewCore);
1335

1436
const urlMatch = /url "([^"]+)"/g.exec(currentFormula.content);
1537
const shaMatch = /sha256 "([^"]+)"/g.exec(currentFormula.content);

0 commit comments

Comments
 (0)