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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help! Memory not freeing when receiving multipart files when ERR_STREAM_PREMATURE_CLOSE #876

Open
Kuyumee opened this issue May 4, 2023 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@Kuyumee
Copy link

Kuyumee commented May 4, 2023

馃挰 Memory not freeing when receiving multipart files when ERR_STREAM_PREMATURE_CLOSE

How can I make Fastify clear up memory when an error occurs during request.saveRequestFiles() specifically ERR_STREAM_PREMATURE_CLOSE?

I have tried below code but it still doesn't free up memory

  let files;

  try {
    files = await request.saveRequestFiles();
  } catch (e) {
    console.log("Error saving files", e);
    await request.cleanRequestFiles();
    reply.code(500).send("Internal Server Error");
    return;
  }

GitHub

The graph shows that it takes half a day for the uploaded data to be released from memory
image

Your Environment

  • node version: v16.17.0
  • fastify version: ^4.17.0
  • os: Windows
@Kuyumee Kuyumee added the help wanted Extra attention is needed label May 4, 2023
@Eomm
Copy link
Member

Eomm commented May 4, 2023

Could you try to force the GC?
https://stackoverflow.com/a/30654451/3309466

(usually, V8 will clean the memory when necessary - for this reason chrome uses so much RAM actually)

@climba03003
Copy link
Member

@Eomm Would it be something related to my comment? Some resources is not cleanup properly, so it hold the reference of unconsumed stream.

fastify/fastify-multipart#436 (review)

@Eomm
Copy link
Member

Eomm commented May 4, 2023

mmm it seems so 馃憤馃徏
I missed that PR - we should give it priority a bit

@Kuyumee
Copy link
Author

Kuyumee commented May 5, 2023

Could you try to force the GC? https://stackoverflow.com/a/30654451/3309466

(usually, V8 will clean the memory when necessary - for this reason chrome uses so much RAM actually)

Forcing GC doesn't seem to free the memory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants