Skip to content

v2.1.0: Better cleanup on error

Latest
Compare
Choose a tag to compare
@rafasofizada rafasofizada released this 21 Jul 10:46
· 3 commits to master since this release
e1453eb

[2.1.0] - 2023-07-21

Changed

  • Cleanup process on request errors. Previously, only request.unpipe() was called on error. Now, an approach inspired by Multer source code was taken:
    • Unpipe the request stream from the parser

    • Remove all event listeners from the parser

    • Resume the request stream.

      • Why req.resume() and not req.pause()?

        • Pausing causes the internal Node.js TCP stack buffers to overflow, backpressure is propagated
          through the network, TCP congestion control kicks in, and may probably slow down the network (?)
        • Resuming doesn't consume any additional memory, and any CPU usage is negligible (networks are much slower than CPUs)
      • Why not req.destroy()?

        • I'm actually not sure. I think it's better to leave it up to the user to decide when and how to close the request. A simple res.end() should be enough.