getSession: an unhandled rejection of bufferOrPathPromise ends Node when an external data download fails

Open Beginner friendly
#1,946 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@chessing234 is already working on this.

Since Nov 20, 2026.

  • #1958 by @chessing234 — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript, node.js

Research direction

Read packages/transformers/src/models/session.js around lines 93–126, where getCoreModelFile(...) and getModelDataFiles(...) are awaited. Reproduce with the issue’s cached model files and dtype: 'fp32' against an unavailable remote host. Done when the caller’s try/catch handles the download failure and the Node process reaches the end normally; the issue gives no test file to run.

Written by the indexing model from the issue text.

Description

System Info
  • @huggingface/transformers 4.3.2 (dist/transformers.node.mjs). The same code is on main at 205e9c251162: session.js#L93-L126
  • Node.js 22.23.5 and 26.13.0, Windows 11
Environment/Platform
  • Server-side (e.g., Node.js, Deno, Bun)
Description

getSession starts getCoreModelFile(...) and keeps the promise in bufferOrPathPromise (L93). It then awaits getModelDataFiles(...) (L97) and awaits bufferOrPathPromise only at L126. When getModelDataFiles rejects, getSession exits before L126. The rejection of bufferOrPathPromise then has no handler. Node reports an unhandled rejection and ends the process with exit code 1. The caller's try/catch around pipeline() does not prevent the exit.

It needs a dtype whose model uses external data (use_external_data_format), so that getModelDataFiles fetches something. With dtype: 'q8' on the same model, the error is caught normally.

Reproduction
  1. Cache only the JSON files of onnx-community/Qwen3-Embedding-0.6B-ONNX (config.json, tokenizer.json, tokenizer_config.json) under env.cacheDir. Leave onnx/ absent.
  2. Run:
import { env, pipeline } from '@huggingface/transformers';
env.cacheDir = './cache/';
env.remoteHost = 'http://127.0.0.1:59999/'; // a closed port
try {
  await pipeline('feature-extraction', 'onnx-community/Qwen3-Embedding-0.6B-ONNX', { dtype: 'fp32' });
} catch (e) {
  console.log('CAUGHT:', e.message);
}
console.log('reached end of script');

Expected: CAUGHT: fetch failed, then reached end of script, exit code 0.
Observed (exit code 1, no CAUGHT line):

node:internal/process/promises:324
    triggerUncaughtException(err, true /* fromPromise */);
    ^
[TypeError: fetch failed] {
  [cause]: Error: connect ECONNREFUSED 127.0.0.1:59999

dtype: 'fp16' gives the same result. Node 22 gives the same exit code.

Control: with bufferOrPathPromise.catch(() => {}); added after L93 in dist/transformers.node.mjs, the same script prints CAUGHT: fetch failed and reached end of script, and exits 0.

Suggested fix

Attach a handler when the promise is created, and keep the await at L126:
const bufferOrPathPromise = getCoreModelFile(...); bufferOrPathPromise.catch(() => {});
Or await both together: Promise.all([getCoreModelFile(...), getModelDataFiles(...)]).

Related: #1801 and #1804 fixed a failure of an external data download in model-loader.js. This one is in session.js.

Dominant language
JavaScript
Stars
16.4k
Forks
1.2k
Avg merge
4d 11h
Merged PRs (30d)
10

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from huggingface/transformers.js

All issues in huggingface/transformers.js

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.