Skip to content

HTTPParser inhibits garbage collection on keep-alive connections #9668

Closed
@jbellenger

Description

  • Version: v7.0.0
  • Platform: Darwin hostname redacted 15.6.0 Darwin Kernel Version 15.6.0: Thu Sep 1 15:01:16 PDT 2016; root:xnu-3248.60.11~2/RELEASE_X86_64 x86_64

I'm not too familiar with node internals, so please correct any details that I may have gotten wrong.

HTTPParser objects appear to be created on a per-socket basis, and retain an incoming reference to an IncomingMessage. The incoming reference is kept around even after the message has been completely parsed and handled, making it un-gc-able for as long as the underlying socket remains open.

At Twitter, we've found that this can contribute to high memory usage when:

  • node is running behind a large pool of proxies with keep-alive connections to our service
  • using express locals to store a large chunk of application state on the request.

In this environment, already-handled messages are unable to be garbage collected until either a new request comes in on the existing socket or the connection is closed.

I put together a small demo of this issue at jbellenger/node-message-retention

Metadata

Assignees

No one assigned

    Labels

    httpIssues or PRs related to the http subsystem.memoryIssues and PRs related to the memory management or memory footprint.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions