Skip to content

[ISSUE] Investigate and Handle "Premature close" Error in StreamableFile Response #1229

@marrouchi

Description

@marrouchi

Description:

We are encountering the following error in the logs:

[Nest] 124  - 07/11/2025, 8:22:54 AM   ERROR [StreamableFile] Premature close  
Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close  
    at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)  
    at new NodeError (node:internal/errors:405:5)  
    at ServerResponse.onclose (node:internal/streams/end-of-stream:159:30)  
    at ServerResponse.emit (node:events:529:35)  
    at emitCloseNT (node:_http_server:1019:10)  
    at Socket.onServerResponseClose (node:_http_server:278:5)  
    at Socket.emit (node:events:529:35)  
    at TCP.<anonymous> (node:net:350:12)  
    at TCP.callbackTrampoline (node:internal/async_hooks:128:17)

Context:

This error likely occurs when using StreamableFile to return a file response, and the connection is closed prematurely before the stream finishes. This could be due to client cancellation, network interruptions, or a bug in the streaming logic.

Metadata

Metadata

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