My issue:
We are building an app where we have front facing HTTP server which performs a proxy pass to a STREAM server. And thereby delivering a stream service over HTTP just like a websocket connection (it will be longed lived upgraded connection).
The actual Problem: Over a period of time we see a memory buildup when clients connect/reconnect and even after the disconnect of these clients, we do not see the memory getting freed up for these nginx worker processes. Is there any known caviates when using HTTP server against the STREAM server.
How I encountered the problem:
Upon multiple client connect/reconnect we observed memory build up for Nginx worker process, even after disconnect of these clients.
Solutions I’ve tried:
We need to know if this a known issue, if not how do we debug and track the memory being held up with HTTP and STREAM server.
What are the best practices to follow to debug and overcome this problem?
Version of NGINX or NGINX adjacent software (e.g. NGINX Gateway Fabric):
1.26.3
Deployment environment:
Centos 7.9
Minimal NGINX config to reproduce your issue (preferably running on https://tech-playground.com/playgrounds/nginx for ease of debugging, and if not as a code block): (Tip → Run nginx -T to print your entire NGINX config to your terminal.)
Below is the snippet of config we are using:
http {
server{
...
location /my-stream {
proxy_pass http://$my_upstream:7890;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Client-IP $remote_addr;
}
}
}
stream {
server {
# Listen for connection from nginx https server
listen 7890 reuseport;
listen [::]:7890 reuseport;
proxy_pass $upstream_server;
}
}
NGINX access/error log: (Tip → You can usually find the logs in the /var/log/nginx directory.)
We captured below logs corresponding to memory operations from nginx debug logs for the use case where we connect and then disconnect the client.
When client connected:
2025/07/09 04:59:17 [debug] 1041#0: *32 malloc: 59284410:1024
2025/07/09 04:59:17 [debug] 1041#0: *32 free: 59284410
2025/07/09 04:59:17 [debug] 1041#0: *32 malloc: 59284410:1024
2025/07/09 04:59:17 [debug] 1041#0: *32 malloc: 59294F40:4096
2025/07/09 04:59:17 [debug] 1041#0: *32 free: 59294F40
2025/07/09 04:59:17 [debug] 1041#0: *32 malloc: 59294CE8:4096
2025/07/09 04:59:17 [debug] 1041#0: *32 free: 59294CE8
2025/07/09 04:59:17 [debug] 1041#0: *32 free: 59294E20, unused: 88
2025/07/09 04:59:17 [debug] 1041#0: *35 malloc: 59297FA8:16384
2025/07/09 04:59:17 [debug] 1041#0: *36 malloc: 5929BFB0:16384
2025/07/09 04:59:17 [debug] 1041#0: *35 free: 59294B80, unused: 216
2025/07/09 04:59:17 [debug] 1041#0: *32 malloc: 59297FA8:4096
2025/07/09 04:59:17 [debug] 1041#0: *32 malloc: 5929FFB8:16384
2025/07/09 04:59:17 [debug] 1041#0: *32 malloc: 5929A738:4096
When client disconnected:
2025/07/09 04:59:37 [debug] 1041#0: *36 free: 59295250, unused: 216
2025/07/09 04:59:37 [debug] 1041#0: *32 free: 592942B0, unused: 88
After some 1-2 mins:
2025/07/09 05:01:37 [debug] 1041#0: slab free: F0071000
2025/07/09 05:01:37 [debug] 1041#0: slab free: F0071100
2025/07/09 05:01:37 [debug] 1041#0: *37 malloc: 592A79F0:1024
2025/07/09 05:01:37 [debug] 1041#0: *37 malloc: 592A89B8:16384
2025/07/09 05:01:37 [debug] 1041#0: *37 free: 592A5340, unused: 0
2025/07/09 05:01:37 [debug] 1041#0: *37 free: 5929B740, unused: 3308
2025/07/09 05:01:37 [debug] 1041#0: *37 free: 592A89B8
2025/07/09 05:01:37 [debug] 1041#0: *37 free: 592A79F0
2025/07/09 05:01:37 [debug] 1041#0: *37 free: 592950B0, unused: 24
2025/07/09 05:01:37 [debug] 1041#0: *37 free: 5928EF10, unused: 136
2025/07/09 05:01:37 [debug] 1041#0: *38 malloc: 592A7670:1024
2025/07/09 05:01:37 [debug] 1041#0: *38 malloc: 592AA0D8:4096
2025/07/09 05:01:37 [debug] 1041#0: *38 free: 592AA0D8
2025/07/09 05:01:37 [debug] 1041#0: *38 malloc: 592AC0E8:16384
2025/07/09 05:01:37 [debug] 1041#0: *38 malloc: 592B00F0:4096
2025/07/09 05:01:37 [debug] 1041#0: *38 free: 592B00F0
2025/07/09 05:01:37 [debug] 1041#0: *38 free: 00000000
2025/07/09 05:01:37 [debug] 1041#0: *38 free: 592A5340, unused: 4
2025/07/09 05:01:37 [debug] 1041#0: *38 free: 592AB0E0, unused: 1760
2025/07/09 05:01:37 [debug] 1041#0: *38 free: 592B1110, unused: 2032
2025/07/09 05:01:37 [debug] 1041#0: *38 free: 592A7670
2025/07/09 05:01:37 [debug] 1041#0: *38 hc free: 00000000
2025/07/09 05:01:37 [debug] 1041#0: *38 free: 592AC0E8
2025/07/09 05:01:37 [debug] 1041#0: *38 malloc: 592A7670:1024
2025/07/09 05:01:37 [debug] 1041#0: *38 free: 592A7670
2025/07/09 05:01:37 [debug] 1041#0: *38 free: 00000000
2025/07/09 05:01:37 [debug] 1041#0: *38 free: 592950B0, unused: 24
2025/07/09 05:01:37 [debug] 1041#0: *38 free: 5928F420, unused: 136