-
Notifications
You must be signed in to change notification settings - Fork 3
Fix timeout on deep repository parsing with depth limiting and concurrency control #16
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: DSYZayn <[email protected]>
… repos Co-authored-by: DSYZayn <[email protected]>
Co-authored-by: DSYZayn <[email protected]>
…t depth Co-authored-by: DSYZayn <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds concurrency control and recursion depth limiting to the metadata fetching functionality to prevent timeouts when parsing extremely deep repository structures on HuggingFace.
Key changes:
- Implements a
limitConcurrencyfunction to control concurrent API requests (max 5 concurrent) - Adds maximum recursion depth limit (10 levels) with early termination
- Refactors the main function to use an internal implementation with depth tracking
Reviewed Changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/api/getMetaData.js | Adds concurrency control and depth limiting to prevent timeouts |
| README.md | Documents the new 10-level depth limit and 5 concurrent subdirectory processing |
| readme/README.zh-CN.md | Chinese documentation for depth and concurrency limits |
| readme/README.zh-TW.md | Traditional Chinese documentation for depth and concurrency limits |
| dist/index.js | Minified production build reflecting the source code changes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/api/getMetaData.js
Outdated
| const promise = handler(item).then((result) => { | ||
| executing.delete(promise); | ||
| return result; | ||
| }); | ||
|
|
||
| results.push(promise); | ||
| executing.add(promise); |
Copilot
AI
Nov 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indexOf operation on line 14 will fail to find the promise because it's called before the promise is added to the executing array. This creates a race condition where the promise may not be properly removed from the tracking array. Store the promise first, then create the cleanup handler, or use a different approach like tracking with a Map or wrapping in an immediately resolved promise.
| const promise = handler(item).then((result) => { | |
| executing.delete(promise); | |
| return result; | |
| }); | |
| results.push(promise); | |
| executing.add(promise); | |
| let resolveWrapper; | |
| const wrapperPromise = new Promise((resolve, reject) => { | |
| resolveWrapper = resolve; | |
| }); | |
| executing.push(wrapperPromise); | |
| const promise = handler(item) | |
| .then((result) => { | |
| executing.splice(executing.indexOf(wrapperPromise), 1); | |
| resolveWrapper(result); | |
| return result; | |
| }) | |
| .catch((err) => { | |
| executing.splice(executing.indexOf(wrapperPromise), 1); | |
| // propagate error to wrapperPromise | |
| resolveWrapper(); // resolve to allow Promise.race to proceed | |
| throw err; | |
| }); | |
| results.push(promise); |
Co-authored-by: DSYZayn <[email protected]>
Co-authored-by: DSYZayn <[email protected]>
…imit) Co-authored-by: DSYZayn <[email protected]>
| */ | ||
| export default async function getMetaData(basePath, filepath) { | ||
| return getMetaDataInternal(basePath, filepath, 0, 10); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good to me but you need to adapt my unit test scripts
Repositories with deeply nested directories (e.g.,
blanchon/ETCI-2021-Flood-Detection) timeout due to unbounded recursive API calls viaPromise.all.Changes
Added depth limiting
Added concurrency control
Implementation
Documentation
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
hf-mirror.comcurl -s REDACTED(dns block)curl -H Accept: application/json REDACTED(dns block)node --experimental-vm-modules --trace-warnings node_modules/jest/bin/jest.js(dns block)huggingface.cocurl -H Accept: application/json REDACTED(dns block)registry.npmmirror.comnpm install(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.