Skip to content

Uncatchable ERR_STREAM_PREMATURE_CLOSE in @aws-sdk/eventstream-handler-node crashes Node.js process #7496

@monarchwadia

Description

@monarchwadia

Describe the feature

Problem

When using @aws-sdk/client-transcribe-streaming with expired credentials, an ERR_STREAM_PREMATURE_CLOSE error is thrown in a callback context that cannot be caught by try/catch, promise handlers, or stream error listeners. This causes an unavoidable Node.js process crash.

Impact

Impossible to build resilient production applications when stream errors crash the entire server instead of allowing graceful error handling.

Originating file

@aws-sdk/[email protected]/dist-cjs/index.js:89

stream.pipeline(payloadStream, signingStream, request.body, (err) => {
    if (err) {
        throw err;  // ⚠️ Throws in callback, bypasses all error handling
    }
});

Reproduction

  1. Create TranscribeStreamingClient with expired credentials
  2. Start streaming with StartStreamTranscriptionCommand
  3. Observe uncaught exception crash

Current Workaround

process.on('uncaughtException', (error: Error) => {
  if ((error as any).code === 'ERR_STREAM_PREMATURE_CLOSE') {
    console.error('Stream error:', error)
    return // Prevent crash
  }
  throw error
})

Use Case

Impossible to build resilient production applications when stream errors crash the entire server instead of allowing graceful error handling.

Proposed Solution

  1. Use promises or event emitters instead of killing the raw stream like this.
  2. On the thrown error, add error.source = '@aws-sdk/eventstream-handler-node' for identification
  3. Document that process.on('uncaughtException') is required

Other Information

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

SDK version used

"@aws-sdk/client-transcribe-streaming": "^3.917.0",

Environment details (OS name and version, etc.)

Node.js v23.9.0, Mac OS 15.6.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestNew feature or enhancement. May require GitHub community feedback.needs-triageThis issue or PR still needs to be triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions