isomorphic-git / isomorphic-git/isomorphic-git
Code resolving tag refs crashes in Linux
- Dominant language
- JavaScript
- Stars
- 8.4k
- Forks
- 491
- Avg merge
- 2h 53m
- Merged PRs (30d)
- 7
Description
We're using isomorphic-git 1.7.8 with node 10.22.1. A CircleCI job running in a Linux docker image with 4 or 8 GB is killed because it runs out of memory. We have a piece of code that resolves git references in parallel. In a standalone script, this looks as follows:
```
const fs = require('fs');
const git = require('isomorphic-git');
/**
* Returns the name of the current branch. If `HEAD` is at a tag, the name of the tag
* will be returned instead.
*
* @param {string} dir working tree directory path of the git repo
* @returns {Promise} current branch or tag
*/
async function getBranch(dir) {
// current branch name
const currentBranch = await git.currentBranch({ fs, dir, fullname: false });
// current commit sha
const rev = await git.resolveRef({ fs, dir, ref: 'HEAD' });
// reverse-lookup tag from commit sha
const allTags = await git.listTags({ fs, dir });
const tagCommitShas = await Promise.all(allTags.map(async (tag) => {
const oid = await git.resolveRef({ fs, dir, ref: tag });
const obj = await git.readObject({ fs, dir, oid });
// annotated or lightweight tag?
return obj.type === 'tag' ? {
tag,
sha: await git.resolveRef({ fs, dir, ref: obj.object.object }),
} : { tag, sha: oid };
}));
const tag = tagCommitShas.find((entry) => entry.sha === rev);
return typeof tag === 'object' ? tag.tag : currentBranch;
}
getBranch('.')
.then((b) => { console.log(b); })
.catch((e) => { console.log(e) });
```
The cloned git repo passed in `dir` has 414 tags, and is located here: https://github.com/adobe/helix-pages. I can reproduce the crash with above script in a docker image called `circleci/node:10-stretch` on my local Docker Desktop.
Note that the issue disappears when I change the `await Promise.all(allTags.map(...))` construct into a for loop.
Contributor guide
Assessment
This issue has not been assessed yet.