Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 of 4 tasks
ondrejpar opened this issue Aug 26, 2024 · 0 comments
Open
2 of 4 tasks

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

ondrejpar opened this issue Aug 26, 2024 · 0 comments

Comments

@ondrejpar
Copy link

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.

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

No branches or pull requests

8 participants
@WoH @ondrejpar and others