Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Cannot create a new GitHub Tree: Server Error #246

Closed
dgokcin opened this issue Sep 7, 2022 · 11 comments
Closed

Error: Cannot create a new GitHub Tree: Server Error #246

dgokcin opened this issue Sep 7, 2022 · 11 comments
Labels
bug Something isn't working released

Comments

@dgokcin
Copy link

dgokcin commented Sep 7, 2022

🐞 Describe the bug

Hello when I am trying to use the action with a GitHub App, I am having this error. Any help is appreciated.

πŸ“š To reproduce

πŸ’‘ Expected behavior

A PR against the specified branch to be created.

πŸ–ΌοΈ Screenshots

image

image

βš™οΈ Environment

@v1

πŸ“‹ Additional context

No response

@dgokcin dgokcin added the bug Something isn't working label Sep 7, 2022
@sammcj
Copy link
Contributor

sammcj commented Oct 2, 2022

I'm getting this as well @BetaHuhn on the latest version of this Action.

Example repo (you can probably fork and try syncing to your fork) - https://github.com/sammcj/github-app-installation-token/

This repo is a Github Action/App so it contains a node_modules folder as is required by Github.

Debug logs:

##[debug]Creating missing blobs on GitHub
##[debug]EXEC: "git ls-tree -r --full-tree b4ef3810621aa63ec702455a5ca7a85ae0c0d61d~1" IN tmp-1664748747018/github.com/sammcj/github-app-installation-token@main
##[debug]EXEC: "git ls-tree -r --full-tree b4ef3810621aa63ec702455a5ca7a85ae0c0d61d" IN tmp-1664748747018/github.com/sammcj/github-app-installation-token@main
##[debug]Creating a GitHub tree
Error: Cannot create a new GitHub Tree: Server Error
##[debug]{"name":"HttpError","status":502,"response":{"url":"https://api.github.com/repos/sammcj/github-app-installation-token/git/trees","status":502,"headers":{"connection":"close","content-length":"32","content-type":"application/json","date":"Sun, 02 Oct 2022 22:13:25 GMT","etag":"\"6339ff8e-20\"","server":"GitHub.com","vary":"Accept-Encoding, Accept, X-Requested-With","x-github-request-id":"0402:35D2:35F8CBB:6F07944:633A0CF8"},"data":{"message":"Server Error"}},"request":{"method":"POST","url":"https://api.github.com/repos/sammcj/github-app-installation-token/git/trees","headers":{"accept":"application/vnd.github.v3+json","user-agent":"octokit-core.js/3.6.0 Node.js/12.22.7 (linux; x64)","authorization":"token [REDACTED]","content-type":"application/json; charset=utf-8"},"body":"{\"tree\":[{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"92322b87f8390109c339c6caf1be64216e402a69\",\"path\":\".devcontainer/devcontainer.json\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"10d776365b3a8859c1f9af6a5ca8061fb85679b7\",\"path\":\".editorconfig\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"7c7e89bf7350249a807e92be77b43b5da4f63c2a\",\"path\":\".eslintrc.cjs\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"f40d39cf5f5a830bbaddfa538a2d4bfbda311a59\",\"path\":\".github/config/labeller.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"be56be9f0ad9508377e172b83015c6a54121803f\",\"path\":\".github/config/labels.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"5dfd89193270342d48898ca73936b2fa1c6157be\",\"path\":\".github/pull_request_template.md\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"7505f9e98779ba82be477d5dd7b6abf540b99954\",\"path\":\".github/workflows/bump-version.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"9c18839f108943554e1f8a51aa9bbc5f162cb416\",\"path\":\".github/workflows/codeball.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"9e99baca685ba42523c4572514dfdfe95b322e8f\",\"path\":\".github/workflows/codeql-analysis.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"0b9777f944266975da74b2f0d788880ec34f0a68\",\"path\":\".github/workflows/detect-secrets.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"1a8a765ddcb275495254fdf9d9b7628718f48d40\",\"path\":\".github/workflows/label-sync.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"172dd0b9e52ac1490a06eacd628afac0d53582c3\",\"path\":\".github/workflows/lint-codeowners.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"f18d105e7528f3b3dd953d421c0a9e2fc04cef21\",\"path\":\".github/workflows/lint-docker.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"dd9a01abc4b1be1cef31c3835ba92fcdaac7fb32\",\"path\":\".github/workflows/lint-pr-actions-skip.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"72bf9a02d2c43240d594b259ebbe170f82929c55\",\"path\":\".github/workflows/lint-pr-actions.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"1573c3ac80cdd0bd97577b429f29b0e6caddff9e\",\"path\":\".github/workflows/lint-pr-markdown.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"58c9312d24db5eda4f05a91547e5c7f4f4107f55\",\"path\":\".github/workflows/lint-shell.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"94e2c9890c49ba6bf4aae111f9651c47639cbdcb\",\"path\":\".github/workflows/lint-tf.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"54071c3e93b3ce19be8d550f6a4302420e50f02b\",\"path\":\".github/workflows/pr-labeller.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"e31f14cddcd183ba0e23604ed91daa5435d66193\",\"path\":\".github/workflows/pre-commit-update.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"8422beb9c6075cc6b8ae148ec636b4338ff2ad55\",\"path\":\".github/workflows/pre-commit.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"106b98578a1283ca68978b7e57b1c69823c38a25\",\"path\":\".github/workflows/release-only.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"dcc98dc47e68f710bd3c83ec4b5f38eb1004d15a\",\"path\":\".github/workflows/test_failure_organisation_not_installed.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"f84970b8f21b8d026cbcca7c314123fa65686566\",\"path\":\".github/workflows/test_failure_repository_not_installed.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"03434179ab15596734ed7904b7d89a83870e36a2\",\"path\":\".github/workflows/test_organisation_installed.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"d631cd3e61140665a914eb3af67791fe75baf12c\",\"path\":\".github/workflows/test_repository_installed.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"587c112c1db6d62a3b1101fd70cf99b453dfcf08\",\"path\":\".github/workflows/test_repository_installed_limited.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"32f9e2e06e23169cb23359dab54f9eeb533e8548\",\"path\":\".github/workflows/todo.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"4cce5d3fc8e468fee466d0e21996e99bedf29842\",\"path\":\".github_application\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"25e959123d2e11b325836de94e755e9a08f68dec\",\"path\":\".gitignore\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"6f7f377bf5148f8b722619c65f29de2c2d204bee\",\"path\":\".nvmrc\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"698f7e90d0f52460bb0f592e1608d0ef486f428b\",\"path\":\".prettierrc.cjs\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"2bfef5b0f511aa1d6d4f21ae6ac2e01b06f9ce4e\",\"path\":\".whitesource\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"773f486871e48e8eeb3dc26cb837da0550ea36cc\",\"path\":\"CONTRIBUTING.md\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"02c729d03ad07cc69bffb4c38e16514fec1e9871\",\"path\":\"LICENSE\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"681b0c2d272ed5fdd386cb4ac986d29ed94417e2\",\"path\":\"README.md\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"328f6da99f704a0a59f88abea31efa00222d4719\",\"path\":\"SECURITY.md\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"4270d653e04fed6303cd8b5d7c8359625043f897\",\"path\":\"action.yml\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"a4e592278008ad0fdbcb4c73192953575a0fcc5f\",\"path\":\"dist/index.js\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"c4aab65d49dcf49178966553558994c09c8dbef6\",\"path\":\"dist/index.js.cache\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"04dbbc12fbf83aac217ccb2b5300dcf1267983e5\",\"path\":\"dist/index.js.cache.js\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"f80836cae09dd6aad9c44970e67d145ca14c4fb6\",\"path\":\"index.js\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"3cab96ea80181d18175043b8796aa7c93e668905\",\"path\":\"jest.config.js\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"20028cbc5320d931ffaffb2d5b0242893580b93e\",\"path\":\"lib/github-application.js\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"9253057dd3cd697cfb98fb61cfa7ba33671fe4c0\",\"path\":\"lib/github-application.test.js\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"a9487a7dc098f549818cb99a00bb70fb9bba01cc\",\"path\":\"lib/private-key.js\"},{\"mode\":\"120000\",\"type\":\"blob\",\"sha\":\"f2a54ffda15b37a6de4d06d458270ea281761f31\",\"path\":\"node_modules/.bin/_mocha\"},{\"mode\":\"120000\",\"type\":\"blob\",\"sha\":\"cf76760386200fb3e0ff9c6827bef9c9fc0305b5\",\"path\":\"node_modules/.bin/acorn\"},{\"mode\":\"120000\",\"type\":\"blob\",\"sha\":\"810e4bcb32af34e41aa631d9bc516e2e5ed8b765\",\"path\":\"node_modules/.bin/eslint\"},{\"mode\":\"120000\",\"type\":\"blob\",\"sha\":\"7d29baaae6e8ce157b174699a9d2f25909ac690e\",\"path\":\"node_modules/.bin/eslint-config-prettier\"},{\"mode\":\"120000\",\"type\":\"blob\",\"sha\":\"5fed16be3901e4feedf972d665e8bcdf2aefdde2\",\"path\":\"node_modules/.bin/flat\"},{\"mode\":\"120000\",\"type\":\"blob\",\"sha\":\"2a8eb5e0c91c98b3a33d74bf79f4766ff4bae653\",\"path\":\"node_modules/.bin/he\"},{\"mode\":\"120000\",\"type\":\"blob\",\"sha\":\"9dbd010d470368b942148cb9ec3acf02d7aac993\",\"path\":\"node_modules/.bin/js-yaml\"},{\"mode\":\"120000\",\"type\":\"blob\",\"sha\":\"c2c121b9cd24ac0c37ebc96ce0c0ec425c874819\",\"path\":\"node_modules/.bin/mocha\"},{\"mode\":\"120000\",\"type\":\"blob\",\"sha\":\"e2be547bcb206b59b72832a11187f6236a5a48ce\",\"path\":\"node_modules/.bin/nanoid\"},{\"mode\":\"120000\",\"type\":\"blob\",\"sha\":\"e05914af1c1a13e3c03da0571985fd8a25a5191f\",\"path\":\"node_modules/.bin/ncc\"},{\"mode\":\"120000\",\"type\":\"blob\",\"sha\":\"6f8415ec58dffcb931a5808d19e3c39a0430f581\",\"path\":\"node_modules/.bin/node-which\"},{\"mode\":\"120000\",\"type\":\"blob\",\"sha\":\"a478df38348be9d500399ed036f68ff5c9a4567e\",\"path\":\"node_modules/.bin/prettier\"},{\"mode\":\"120000\",\"type\":\"blob\",\"sha\":\"b6afda6c753f1fb771d1ae4bb413ee11c4cd0037\",\"path\":\"node_modules/.bin/resolve\"},{\"mode\":\"120000\",\"type\":\"blob\",\"sha\":\"4cd49a49ddfc17a0c038a9c11d3abbb8181dc025\",\"path\":\"node_modules/.bin/rimraf\"},{\"mode\":\"120000\",\"type\":\"blob\",\"sha\":\"5aaadf42c4a8b282cbf6cc5c73e6ea0beedd2d46\",\"path\":\"node_modules/.bin/semver\"},{\"mode\":\"120000\",\"type\":\"blob\",\"sha\":\"dc0a4f8391b46b0384357bc3d055e18f7d9a4d97\",\"path\":\"node_modules/.bin/sort-package-json\"},{\"mode\":\"120000\",\"type\":\"blob\",\"sha\":\"0863208a6a1fe7ba964993a1a398794c4021ae19\",\"path\":\"node_modules/.bin/tsc\"},{\"mode\":\"120000\",\"type\":\"blob\",\"sha\":\"f8f8f1a0c33562942ab214430b7878ee378cfdd8\",\"path\":\"node_modules/.bin/tsserver\"},{\"mode\":\"120000\",\"type\":\"blob\",\"sha\":\"588f70ecc5fc9a9d7c80d009fd555d2ec8cd9ba7\",\"path\":\"node_modules/.bin/uuid\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"b9e585a163f3d5118fd2513f4c4a649e521f2e6d\",\"path\":\"node_modules/.package-lock.json\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"dbae2edb2c8ca2cf3ce4abe863b6e6dff5970f99\",\"path\":\"node_modules/@actions/core/LICENSE.md\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"3c20c8ea56fbac106622b228ed661da95ef38319\",\"path\":\"node_modules/@actions/core/README.md\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"53f8f4b8d46925f9824f39d185a77aa03116c524\",\"path\":\"node_modules/@actions/core/lib/command.d.ts\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"0b28c66b8fd07b11c2750200bb25efeb9e1facf9\",\"path\":\"node_modules/@actions/core/lib/command.js\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"51c7c6375108fc7fbe4489ae0d9c890dbef791ab\",\"path\":\"node_modules/@actions/core/lib/command.js.map\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"1defb5722bbbdfeb1074f2baf14c2f4cb5d73151\",\"path\":\"node_modules/@actions/core/lib/core.d.ts\"},{\"mode\":\"100644\",\"type\":\"blob\",\"sha
.... (continued)

@RichardTMiles
Copy link

RichardTMiles commented Oct 25, 2022

It currently seems that my team is facing this too. I could get it working in a reasonably new repo, but our well-established failed. Note the name .co vs .com
Screen Shot 2022-10-25 at 5 38 43 PM

@RichardTMiles
Copy link

Screen Shot 2022-10-25 at 5 42 23 PM

The app is added for the entire account, and the repo does not contain a node_modules (though it may in history)

RichardTMiles added a commit to RichardTMiles/repo-file-sync-action that referenced this issue Oct 26, 2022
@RichardTMiles
Copy link

Using BetaHuhn/repo-file-sync-action@master vs BetaHuhn/repo-file-sync-action@v1 or BetaHuhn/repo-file-sync-action@latest worked for me

@RichardTMiles
Copy link

Seem's like this still occurs in a very spastic way. Re-running the workflow has solved the issue before.

@sammcj
Copy link
Contributor

sammcj commented Nov 9, 2022

Similar for me too -
image

@DocMarten
Copy link

I'm running into the same problem.
I think this is related to the size of the repository. For the most repositories it runs without problems and only for repositories with a lot of files the error occurs.

The github API return a 502 error for the createTree request.

try {
	const request = await this.github.git.createTree({
		owner: this.repo.user,
		repo: this.repo.name,
		tree
	})
	treeSha = request.data.sha
} catch (error) {
	error.message = `Cannot create a new GitHub Tree: ${ error.message }`
	throw error
}

Error: Cannot create a new GitHub Tree: Server Error
##[debug]{"name":"HttpError","status":502,"response":{"url":"https://api.github.com/repos/.../git/trees","status":502,"headers":{"connection":"close","content-length":"32","content-type":"application/json","date":"Tue, 18 Apr 2023 11:23:08 GMT","etag":""643e7ad2-20"","server":"GitHub.com","vary":"Accept-Encoding, Accept, X-Requested-With","x-github-request-id":"xxx"},"data":{"message":"Server Error"}},"request":{"method":"POST","url":"https://api.github.com/repos/.../git/trees","headers":{"accept":"application/vnd.github.v3+json","user-agent":"octokit-core.js/3.6.0 Node.js/16.16.0 (linux; x64)","authorization":"token [REDACTED]","content-type":"application/json; charset=utf-8"},"body":"{"tree":[{"mode":"100644","type":"blob","sha":"de7b5be2afe111d4fc8325674edc1870e0e6bbef","path":".eslintrc.json"},{"mode":"100644","type":"blob","sha":"5af36ee5af3961f8c6abb758d0155a764c3cc7b4","path":".github/workflows/pr_lint.yaml"},......

Maybe there is another way to determine the tree hash?
@BetaHuhn doesn't previousTree already contain the required sha?

@asafhm
Copy link

asafhm commented Jun 11, 2023

@DocMarten Mine was the same case, and this workaround did the trick for me:

Increase the http.postBuffer default limit (added as a step between the checkout step and the action step):

- run: git config --global http.postBuffer 157286400

(Here I used an arbitrary value of 150MB for example)

@alvarezfr
Copy link
Contributor

Hi, I have just created the PR #321 with a fix for this.

I have done multiple tests and all of them works just fine but if any of you still have this kind of problem you can test it before it is merged. I'm sure that any additional feedback about the fix is welcome, you can test it temporally calling the action from my source branch of the PR: alvarezfr/repo-file-sync-action@fix/github-app-auth-tree.

I'm running into the same problem. I think this is related to the size of the repository. For the most repositories it runs without problems and only for repositories with a lot of files the error occurs.

The github API return a 502 error for the createTree request.

try {
	const request = await this.github.git.createTree({
		owner: this.repo.user,
		repo: this.repo.name,
		tree
	})
	treeSha = request.data.sha
} catch (error) {
	error.message = `Cannot create a new GitHub Tree: ${ error.message }`
	throw error
}

Error: Cannot create a new GitHub Tree: Server Error
##[debug]{"name":"HttpError","status":502,"response":{"url":"https://api.github.com/repos/.../git/trees","status":502,"headers":{"connection":"close","content-length":"32","content-type":"application/json","date":"Tue, 18 Apr 2023 11:23:08 GMT","etag":""643e7ad2-20"","server":"GitHub.com","vary":"Accept-Encoding, Accept, X-Requested-With","x-github-request-id":"xxx"},"data":{"message":"Server Error"}},"request":{"method":"POST","url":"https://api.github.com/repos/.../git/trees","headers":{"accept":"application/vnd.github.v3+json","user-agent":"octokit-core.js/3.6.0 Node.js/16.16.0 (linux; x64)","authorization":"token [REDACTED]","content-type":"application/json; charset=utf-8"},"body":"{"tree":[{"mode":"100644","type":"blob","sha":"de7b5be2afe111d4fc8325674edc1870e0e6bbef","path":".eslintrc.json"},{"mode":"100644","type":"blob","sha":"5af36ee5af3961f8c6abb758d0155a764c3cc7b4","path":".github/workflows/pr_lint.yaml"},......

Maybe there is another way to determine the tree hash? @BetaHuhn doesn't previousTree already contain the required sha?

I have been able to reproduce the problem with a big size repository and a small one, I was revisiting the API documentation and the error and even searching for the problem but I was not able to find any limit or reason why this was failing, but I suspect that this way of doing the tree was hitting a hidden limit in these cases. The PR changes the way the tree is constructed, previously it created a tree with any single file in the commit, but now creates the tree only with the changes and sets the parent commit tree as base_tree in the API.

This produces a smaller request in almost all cases.

@kkantonop
Copy link

@alvarezfr thanks a lot for this! it worked for me!

it would be good to have this merged as we would like to avoid using a custom branch

@BetaHuhnBot
Copy link
Collaborator

πŸŽ‰ This issue has been resolved in version 1.21.1 πŸŽ‰

The release is available on GitHub release

Your semantic-release bot πŸ“¦πŸš€

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

No branches or pull requests

8 participants