openresty / openresty/stream-lua-nginx-module

worker process suffers CPU 100% usage

Aperta
#167 3 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
C
Stelle
749
Fork
210
Merge medio
4h 31m
PR unite (30g)
3

Descrizione

Hello!

The worker process CPU usage could be 100% if we use the following configuration pattern:

stream {
    server {
        listen 3105 reuseport;

        lua_check_client_abort on; # must be enabled

        content_by_lua_block {
            local sock, err = ngx.req.socket(true)

            sock:settimeout(1800 * 1000)

            local readline = sock:receiveuntil("\n")

            while not ngx.worker.exiting() do
                local line, err = readline(1)
                ngx.log(ngx.ERR, "line: ", line)
                if not line then
                    if err then
                        ngx.log(ngx.ERR, err)
                        break
                    end
                else
                    ngx.sleep(5000) -- other yieldable API is also applicable.
                end
            end
        }
    }
 }

Building a connection through nc and sending some characters then closing it, in the meanwhile, observing the CPU usage by top.

$ nc 127.0.0.1 3105
asjdkl
zxckj
^C

Now you can find the CPU usage reaches 100%.

It's irrelevant with the version of ngx_stream_lua, you can reproduce this problem even with the newest OpenResty.

After investigating the internal of stream-lua-nginx-module, I found it was caused by the indefinitely trigger of ngx_stram_lua_check_broken_connection, which doesn't the check ev->pending_eof flag.

BTW, this issue was found by @tianchaijz.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da ngx_stram_lua_check_broken_connection e traccia la gestione degli eventi del worker coinvolta nella configurazione stream fornita. Riproduci il problema con la configurazione nginx e i comandi nc, quindi verifica che la chiusura della connessione non causi più un utilizzo della CPU del worker al 100%.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
c, nginx
Ambito
backend, networking
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
42/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.