A demonstration of gc-resistant http parsing
npm install
npm start
Running npm start will simulate a request/response lifecycle using keep-alive connections. After handling, the program will GC and print the path to a heapsnapshot before exiting. The heapsnapshot can be viewed in chrome dev tools.
The heapsnapshot above shows that after a complete request/response lifecycle and a GC, the server retains a reference to the request (the type shown here is IncomingMessage) after it is no longer useful.
This is problematic as the server may have set properties on the request with the expectation that they would be garbage collected within a reasonable time. This example uses sets a 30MB buffer named REQUEST_LOCAL_DATA on the request, though frameworks like express use the same underlying mechanism to manage request-scoped data
