hyper: 0.14: memory leak

Relates to https://github.com/tokio-rs/axum/issues/1724

Code base: https://github.com/hyperium/hyper/blob/0.14.x/examples/echo.rs (wrapped into project called hyper-leak)

Cargo.toml

[package]
name = "hyper-leak"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
hyper = { version = "0.14", features = ["full"] }
tokio = { version = "1", features = ["full"] }
pretty_env_logger = "0.4"
http-body-util = "0.1.0-rc.2"
futures-util = "0.3.25"

How to reproduce:

  1. Start app cargo build --release ./target/release/hyper-leak

  2. Measure initial memory

ps x -o rss,vsz,command | awk 'NR>1 {$1=int($1/1024)"M"; $2=int($2/1024)"M";}{ print ;}' | grep hyper-leak`
2M 398468M ./target/release/hyper-leak
  1. Run load test for some secs (Load testing tool must be installed: cargo install oha) oha -z 10m -c 500 "http://127.0.0.1:3000/" -d test

(Issue also appears on paths that trigger 404)

  1. Stop load test and measure memory Result: 22M 398750M ./target/release/hyper-leak

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 26 (2 by maintainers)

Most upvoted comments

@lcmgh what was the “another reason” for your prod app?

I used axum-sessions in a way that it created a new in-memory session for each k8s health check call. This accumulated to continously increasing memory usage.

I just slept to manually measure with ps 😃 Will test your code later or tomorrow.