Skip to content

Returning a stream of non-existent file shuts down Node #1664

Description

@ondrejpar

Sorting

  • I'm submitting a ...

    • bug report
    • feature request
    • support request
  • I confirm that I

    • used the search to make sure that a similar issue hasn't already been submit

Expected Behavior

If an error occurs during reading a file returned as Promise<Readable>, (such as, if the file doesn't exist), tsoa should respond with 500 Internal Server Error.

Current Behavior

Node shuts down with:

[Error: ENOENT: no such file or directory, open '/non-existent-file'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/non-existent-file'
}
 ELIFECYCLE  Command failed with exit code 1.

Context (Environment)

Version of the library: 4.1.3
Version of NodeJS: 18.16.0

I actually use pnpm, but I doubt it has anything to do with this.

Steps to reproduce

  @Get('somefile')
  @SuccessResponse(200, "JS module file", "text/plain")
  async getSomeFile(
    @Request() req: ExpressRequest
  ): Promise<Readable> {
    req.res?.setHeader('content-type', 'text/plain');
    return fs.createReadStream('/non-existent-file');
  }

Just call this controller to reproduce the bug.

Detailed Description

Seems that tsoa doesn't add on('error') handler to the stream. I can add my own, but I found no way to respond with error code. If I just log the error in the error handler, the request hangs indefinitely.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions