mirror of
https://github.com/ADD-SP/ngx_waf.git
synced 2026-04-26 14:05:52 +03:00
[GH-ISSUE #75] ngx_http_waf_module 存在内存泄漏 #190
Labels
No labels
MacOS
Nginx
OpenResty
Tengine
bug
documentation
enhancement
needs-investigation
pull-request
question
stale
stale
stale
timeout
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/ngx_waf#190
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @purplegrape on GitHub (Dec 14, 2021).
Original GitHub issue: https://github.com/ADD-SP/ngx_waf/issues/75
操作系统: amazon linux 2
nginx: 1.20.2
ngx_http_waf_module: 6.1.7
使用ngx_http_waf_module 模块之后,内存明显增加,6.1.4之后应该都有类似问题
nginx运行时间较长之后,内存使用量持续增加,到一定程度之后,error日志中报错 “ngx_slab_alloc() failed: no memory”
应该是内存泄漏无疑了。
@purplegrape commented on GitHub (Dec 14, 2021):
nginx -s reload 可回收部分内存,但无法阻止内存增长,重启nginx回收内存更彻底。
@ADD-SP commented on GitHub (Dec 14, 2021):
内存会无限增长么?因为 LTS 版本的内存回收机制是除非共享内存耗尽,否则不会回收,所以曲线应该是一直上升,然后在峰值左右轻微波动。
@ADD-SP commented on GitHub (Dec 14, 2021):
出现错误日志是应该的,应为只有出错才会意识到共享内存不足,然后回收。
@purplegrape commented on GitHub (Dec 14, 2021):
目前配置是 waf_mode STATIC
升级到6.1.7之后,我尝试改为 waf_mode GET POST UA URL 继续观察下
@purplegrape commented on GitHub (Dec 14, 2021):
内存增长到一定程度日志会报错ngx_slab_alloc() failed: no memory ,服务器CPU是4核,nginx 1个master+4个worker进程使用最大内存561m,master基本不占内存,worker吃内存。
current 版本的内存机制是否有改善?是否值得一试?
@ADD-SP commented on GitHub (Dec 14, 2021):
只要不是每次请求多会日志报错就行。
Current 版本的内存回收机制已经改了,每次处理请求后就会回收内存(大概),具体的回收行为由环境决定。比如有 4 个 worker 进程,每个进程处理完每个请求后就有 25% 的概率进行一次内存回收。如果某次处理过程中内存不足,则会采用更激进的回收方式。
@purplegrape commented on GitHub (Dec 14, 2021):
如果真的是因为共享内存增长快速而惰性回收的话,那应该就不是内存泄漏了,但是ngx_slab_alloc() failed: no memory 这个日志很难解释
@ADD-SP commented on GitHub (Dec 14, 2021):
很容易解释,因为只要共享内存耗尽就会有这个日志。
@purplegrape commented on GitHub (Dec 14, 2021):
我只想要一个basic 的版本,能够简单的维护静态规则就好,我去尝试下current 版本看看
@ADD-SP commented on GitHub (Dec 14, 2021):
忘记说了,新的内存回收机制仅限于使用共享内存的功能,即所有需要指定
zone参数的配置项,比如waf_cc_deny。指令waf_cache所使用的内存不是共享内存,所以依然是惰性回收。@ADD-SP commented on GitHub (Dec 14, 2021):
@purplegrape 建议尽快更换为 v10.1.0,刚刚发现内存回收机制并未正常运行,虽然不会导致内存泄漏,但是会退化为惰性回收。
@purplegrape commented on GitHub (Dec 20, 2021):
升级到10.1.0之后,4个workder, 内存直接干到500多m,虽然目前没什么异常,但感觉太废内存了。
配置文件
http {
...
waf on;
waf_mode STD;
waf_rule_path /etc/nginx/ngx_http_waf/rules/;
...
}
@ADD-SP commented on GitHub (Dec 20, 2021):
其实昨天已经发现内存泄漏问题了,只是没时间修复,缓解方法就是 reload。
@purplegrape commented on GitHub (Dec 20, 2021):
可以使用sonarqube之类的静态工具多检查一下代码
真心建议功能不要贪多求全,简单好用才是王道
@ADD-SP commented on GitHub (Dec 20, 2021):
已经在分支
current-dev修复,可以下载重新安装试试。@purplegrape commented on GitHub (Dec 22, 2021):
还是等你发正式版吧
@stale[bot] commented on GitHub (Jan 5, 2022):
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
此 issue 因为最近没有任何活动已经被标记,如果在此之后的一段时间内仍没有任何活动则会被关闭。感谢您对项目的支持。
@ADD-SP commented on GitHub (Jan 7, 2022):
This bug has been fixed in
v6.1.8andv10.1.1.此 bug 已经在
v6.1.8和v10.1.1中修复。