Skip to content

fix(scope-gc), catch version-loading errors #9193

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

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scopes/harmony/modules/in-memory-cache/in-memory-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export type CacheOptions = {
};

export function getMaxSizeForComponents(): number {
return getNumberFromConfig(CFG_CACHE_MAX_ITEMS_COMPONENTS) || 1000;
return getNumberFromConfig(CFG_CACHE_MAX_ITEMS_COMPONENTS) || 500;
}

export function getMaxSizeForObjects(): number {
return getNumberFromConfig(CFG_CACHE_MAX_ITEMS_OBJECTS) || 5000;
return getNumberFromConfig(CFG_CACHE_MAX_ITEMS_OBJECTS) || 3000;
}
23 changes: 19 additions & 4 deletions src/scope/garbage-collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { compact, uniq } from 'lodash';
import { Ref } from './objects';
import { ComponentID, ComponentIdList } from '@teambit/component-id';
import chalk from 'chalk';
import { VersionNotFound } from './exceptions';

const DELETED_OBJECTS_DIR = 'deleted-objects';

Expand Down Expand Up @@ -98,7 +99,7 @@ export async function collectGarbage(thisScope: Scope, opts: GarbageCollectorOpt
logger.console(`[*] total ${componentInsideLanesUniq.length} components inside lanes`);

await pMapSeries(componentInsideLanesUniq, async (comp) => {
const modelComp = await thisScope.getModelComponentIfExist(comp);
const modelComp = await thisScope.getModelComponentIfExist(comp.changeVersion(undefined));
if (!modelComp) return;
await processComponent(modelComp, Ref.from(comp.version), false, true);
});
Expand Down Expand Up @@ -129,7 +130,13 @@ export async function collectGarbage(thisScope: Scope, opts: GarbageCollectorOpt
await pMap(
refsToDelete,
async (ref) => {
const obj = await ref.load(repo);
let obj;
try {
obj = await ref.load(repo);
} catch (err: any) {
if (verbose) logger.console(chalk.red(`error loading ${ref.toString()} ${err.message}`));
return;
}
const id = obj instanceof Version || obj instanceof Source ? '' : obj.id();
if (verbose) logger.console(`ref ${ref.toString()} ${obj.constructor.name} ${obj.getType()} ${id}`);
if (obj instanceof ModelComponent) {
Expand Down Expand Up @@ -229,12 +236,20 @@ export async function collectGarbage(thisScope: Scope, opts: GarbageCollectorOpt

async function processDep(dep: string) {
const depId = ComponentID.fromString(dep);
const modelComp = await thisScope.getModelComponentIfExist(depId);
const modelComp = await thisScope.getModelComponentIfExist(depId.changeVersion(undefined));
if (!modelComp) {
return;
}
refsWhiteList.add(modelComp.hash().hash);
const version = await modelComp.loadVersion(depId.version, repo, false);
let version: Version | undefined;
try {
version = await modelComp.loadVersion(depId.version, repo, false);
} catch (err: any) {
if (err instanceof VersionNotFound) return;
if (err.constructor.name === 'MissingScope') return; // object is corrupted, it's fine to delete it
logger.console(chalk.red.bold(`error loading a flattened dep ${depId.toString()}`));
throw err;
}
if (!version) {
return;
}
Expand Down