Skip to content

Unhandled promise rejection in LiveV2Session constructor crashes the host process #27

Description

@geosigno

Package: @gladiaio/sdk@1.0.4
Runtime: Node.js ≥15 / Bun 1.3.x (any runtime with default Node unhandledRejection exit behavior)

Problem

The LiveV2Session constructor calls this.startSession() without await or .catch(). Internally, startSession() awaits this.initSessionPromise. When the underlying POST /v2/live fails (4xx auth, 429 quota, 5xx, network timeout), the rejection from this fire-and-forget call triggers unhandledRejection — terminating the whole host process.

This happens even when the consumer correctly awaits and catches session.getSessionId(). Two independent consumers of initSessionPromise exist; only the user's one is catchable from outside.

node_modules/@gladiaio/sdk/dist/v2/live/session.js:

constructor({ ... }) {
  // ...
  this.initSessionPromise = this.initSession();   // promise A — consumed by user via getSessionId()
  this.startSession();                            // promise B — fire-and-forget, awaits A internally
}

async startSession() {
  const session = await this.initSessionPromise;  // rejects → unhandled (no .catch on the caller)
  // ...
}

Reproduction

import { GladiaClient } from "@gladiaio/sdk";

const client = new GladiaClient({ apiKey: "invalid-key-xxx" });

try {
  const session = client.liveV2().startSession({
    encoding: "wav/pcm",
    bit_depth: 16,
    sample_rate: 16_000,
    channels: 1,
    language_config: { languages: ["en"], code_switching: false },
  });
  await session.getSessionId();
} catch (err) {
  console.log("Caught as expected:", err);
}

await new Promise((r) => setTimeout(r, 1000));
console.log("Never reached — process exited on unhandledRejection.");

Stack:

HttpError: gladia user not found | <request-id> | 401 | POST /v2/live
  at createHttpError (node_modules/@gladiaio/sdk/dist/network/httpClient.js:41:9)
  at async request (node_modules/@gladiaio/sdk/dist/network/httpClient.js:146:28)

Impact

Any host application running the SDK in a long-lived process is killed entirely by a single failed init — including transient 5xx or network errors with a valid API key. The blast radius is the whole process, not just the SDK consumer feature.

Environment

  • @gladiaio/sdk: 1.0.4
  • Bun: 1.3.13 (darwin arm64)
  • Reproducible with Node ≥15 default unhandledRejection behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions