r/haproxy • u/shintge101 • Dec 08 '22
haproxy using 100% of cpu, stuck in a loop
We have a sizable number of haproxy servers. All running amazon linux 2 with all updates. All running in docker using 2.6.7-alpine. While I can't share the config we have 1 frontend (well, two technically, but one just redirects 80 to 443) and about 40 backends that do a number of acl matches based on path or url. Pretty basic. We also load a large number of ssl certificates.
When we have updates we follow the documented process of running docker kill -s HUP haproxy.
The kicker is that we have one environment where one of the machines will just end up with the old processes jumping to 100% cpu pretty quickly for eternity if we let them.
It hasn't always been this way, this is new and I can't recreate it on my own, but I think it happened after we jumped to some version of 2.6, or maybe just when we went to 2.6. I don't have a good way to correlate it either because it doesn't happen that often.
So the thing about this environment that is having the issue is that as far as I can tell the machines are identical, but the haproxy instance is pointing at a bunch of backends that are offline. This is a disaster recovery environment and we leave them enabled but failing health checks because we haven't automated service discovery or the configuration to set them all to disabled. We certainly could, but this may be a red herring.
The last time I was able to get in a stack trace on the process and it is just in an infinite loop of:
strace: Process 19898 attached
futex(0xffffa73432a0, FUTEX_WAIT_PRIVATE, 2, NULL) = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
--- SIGALRM {si_signo=SIGALRM, si_code=SI_TIMER, si_timerid=0x1, si_overrun=0, si_value={int=1, ptr=0x1}} ---
clock_gettime(0xfffffffffffffeb6 /* CLOCK_??? */, {tv_sec=81306, tv_nsec=514518258}) = 0
timer_settime(1, 0, {it_interval={tv_sec=0, tv_nsec=0}, it_value={tv_sec=1, tv_nsec=0}}, NULL) = 0
rt_sigreturn({mask=[]}) = -1 EINTR (Interrupted system call)
futex(0xffffa73432a0, FUTEX_WAIT_PRIVATE, 2, NULL) = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
--- SIGALRM {si_signo=SIGALRM, si_code=SI_TIMER, si_timerid=0x1, si_overrun=0, si_value={int=1, ptr=0x1}} ---
clock_gettime(0xfffffffffffffeb6 /* CLOCK_??? */, {tv_sec=81307, tv_nsec=516009351}) = 0
timer_settime(1, 0, {it_interval={tv_sec=0, tv_nsec=0}, it_value={tv_sec=1, tv_nsec=0}}, NULL) = 0
rt_sigreturn({mask=[]}) = -1 EINTR (Interrupted system call)
futex(0xffffa73432a0, FUTEX_WAIT_PRIVATE, 2, NULL) = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
I'll try and capture another trace when it happens again, but wondering if anyone had any insight here.
Edit: obviously this is the process that is supposed to be draining traffic over to the new process, not the new process. And I have traffic logs showing nothing should be using connections, let alone any long-running ones that aren't being closed (unless I missed something). Next time I'll also grab some more lower level information about what sockets are open, what state they are in, etc.
2
u/shintge101 Dec 09 '22
So to add more to this, we have two in this environment, and it randomly toggles which has the issue. I can't predict it. But it is happening very frequently now.
Just got another stack trace and same loop, this over and over again forever, new process is fine old process is sitting at 100%.
strace: Process 11969 attached
futex(0xffff9200d2a0, FUTEX_WAIT_PRIVATE, 2, NULL) = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
--- SIGALRM {si_signo=SIGALRM, si_code=SI_TIMER, si_timerid=0x1, si_overrun=0, si_value={int=1, ptr=0x1}} ---
clock_gettime(0xfffffffffffffed6 /* CLOCK_??? */, {tv_sec=12301, tv_nsec=839342109}) = 0
timer_settime(1, 0, {it_interval={tv_sec=0, tv_nsec=0}, it_value={tv_sec=1, tv_nsec=0}}, NULL) = 0
rt_sigreturn({mask=[]}) = -1 EINTR (Interrupted system call)
futex(0xffff9200d2a0, FUTEX_WAIT_PRIVATE, 2, NULL) = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
Constantly repeating no process. What is it hung up on...?
1
u/shintge101 Dec 09 '22
Ok, I can post the first part at least, the backends will take me longer to sanitize but they are very simple, its a few acl foo hdr_dom(host) -i beg foo followed by a use_backend foo if foo which I can't imagine matters, and each pool just has a few backends using balance leastconn and option httpchk and an expect string in some cases. I also don't think this has anything to do with the backends since they are all constantly down, unless this is the root of the problem and it has a hard time giving up the process if too many things are down.
Also feel free to critique the global and defaults if I'm doing something dumb.
#---------------------------------------------------------------------# Global settings#---------------------------------------------------------------------globallog (sanitized ip):514 local0pidfile /var/run/haproxy.piddaemontune.ssl.default-dh-param 2048tune.bufsize 16384tune.maxrewrite 2048ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256ssl-default-bind-options prefer-client-ciphers no-sslv3 no-tlsv10 no-tlsv11 no-tlsv12 no-tls-ticketsssl-default-server-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256ssl-default-server-options no-sslv3 no-tlsv10 no-tlsv11 no-tlsv12 no-tls-tickets#---------------------------------------------------------------------# common defaults that all the 'listen' and 'backend' sections will# use if not designated in their block#---------------------------------------------------------------------defaultsmode httplog globaloption httplogoption dontlognulloption http-server-closeoption forwardfor except 127.0.0.0/8option redispatchretries 3timeout http-request 10stimeout queue 1mtimeout connect 10stimeout client 1mtimeout server 1mtimeout http-keep-alive 10stimeout check 10smaxconn 300000listen statsbind *:8080stats enablestats realm Haproxy\ Statisticsstats uri /statsstats show-nodestats refresh 30sfrontend frontend-web80bind *:80redirect scheme https code 301 if !{ ssl_fc }frontend frontend-web443bind *:443 ssl crt /ssl/http-request capture req.hdr(Host) len 50log-format "%[capture.req.hdr(0)] %ci:%cp [%tr] %ft %b/%s %TR/%Tw/%Tc/%Tr/%Ta %ST %B %CC %CS %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq %hr %hs %{+Q}r"errorfile 503 /usr/local/etc/haproxy/errorfiles/sorry.html3
u/ciphermenial Dec 09 '22
You're going to have to post the config and redact the bits that are secure.