denoland/deno · error · TypeError

BenchContext::end() has already been invoked

Error message

BenchContext::end() has already been invoked

What it means

After verifying and extracting the archive into a sibling staging directory, the atomic rename into the cache location failed, and no concurrently-created valid copy (completion marker) exists at the destination, so cache population is reported failed rather than silently ignored.

Source

Thrown at cli/js/40_bench.js:446

          "The benchmark which this context belongs to is not being executed",
        );
      }
      if (currentBenchUserExplicitStart != null) {
        throw new TypeError(
          "BenchContext::start() has already been invoked",
        );
      }
      currentBenchUserExplicitStart = benchNow();
    },
    end() {
      const end = benchNow();
      if (currentBenchId !== desc.id) {
        throw new TypeError(
          "The benchmark which this context belongs to is not being executed",
        );
      }
      if (currentBenchUserExplicitEnd != null) {
        throw new TypeError("BenchContext::end() has already been invoked");
      }
      currentBenchUserExplicitEnd = end;
    },
  };
}

/** Wrap a user benchmark function in one which returns a structured result. */
function wrapBenchmark(desc) {
  const fn = desc.fn;
  return async function outerWrapped() {
    let token = null;
    const originalConsole = globalThis.console;
    currentBenchId = desc.id;

    try {
      globalThis.console = new Console((s) => {
        op_dispatch_bench_event({ output: s });
      });

View on GitHub (pinned to 89f33cbef2)

Solutions

  1. Delete the cache directory for that backend/target and re-run so it is re-downloaded and re-extracted cleanly
  2. Exclude the Deno/lafney cache from antivirus and sync tools
  3. Check and fix permissions/ownership on the cache root
  4. Avoid simultaneous first-time desktop builds against the same cache, or retry after the other process finishes
Defensive patterns

Strategy: retry

Validate before calling

// ensure the cache root is writable and not synced/scanned before first download
await Deno.mkdir(cacheRoot, { recursive: true });
await Deno.writeFile(join(cacheRoot, '.probe'), new Uint8Array(1));
await Deno.remove(join(cacheRoot, '.probe'));

Try / catch

try {
  await populateLaufeyCache();
} catch (e) {
  if (!/atomic-rename/.test(String(e))) throw e;
  await Deno.remove(cacheDir, { recursive: true }).catch(() => {}); // clear the mangled dir
  await populateLaufeyCache(); // one clean retry re-downloads and re-extracts
}

Prevention

When it happens

Trigger: Filesystem errors on rename: destination held/locked by antivirus or file-sync clients, permission or ownership changes, exotic filesystem rename semantics, or a concurrent process that left the target in a bad state without the marker.

Common situations: Two `deno desktop` builds racing on a cold cache; OneDrive/Dropbox or AV scanning the cache dir; a read-only cache root; interrupted earlier runs.

Related errors


AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16). Data as JSON: /api/errors/0958e05beb001d1a. Report an issue: GitHub.