MagicStack / MagicStack/httptools

`on_url` not called intermittently?

Aperta
#20 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Python
Stelle
1.3k
Fork
107
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

From time to time, my server output an error that let me think that Request.on_url is not called for the current stream.

Here is a small script to reproduce the behaviour:

import asyncio

from httptools import HttpRequestParser


class Request:

    def __init__(self):
        self.EOF = False

    def on_url(self, url: bytes):
        self.on_url_called = True

    def on_message_complete(self):
        self.EOF = True


async def serve(reader, writer):
    chunks = 2 ** 16
    req = Request()
    parser = HttpRequestParser(req)
    while True:
        data = await reader.read(chunks)
        parser.feed_data(data)
        if not data or req.EOF:
            break
    assert req.on_url_called
    writer.write(b'HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nOK')
    writer.write_eof()


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    coro = loop.create_task(asyncio.start_server(serve, '127.0.0.1', 8080))
    server = loop.run_until_complete(coro)
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        print('Bye.')
    finally:
        server.close()
        loop.run_until_complete(server.wait_closed())
        loop.close()

To be run with python file.py

And then benchmark it with something like ab -n 10000 -c 8 'http://127.0.0.1:8080/'

Once every, say, 10000 requests, I get this error:

Task exception was never retrieved
future: <Task finished coro=<serve() done, defined at test_httptools.py:18> exception=AttributeError("'Request' object has no attribute 'on_url_called'",)>
Traceback (most recent call last):
  File "test_httptools.py", line 27, in serve
    assert req.on_url_called
AttributeError: 'Request' object has no attribute 'on_url_called'

Any hint? :)

Thanks!

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

Riproduci il malfunzionamento intermittente utilizzando lo script in test_httptools.py e il benchmark ab descritto nel report. Inizia da HttpRequestParser e parser.feed_data, quindi traccia il percorso dei dati della richiesta fino a Request.on_url. Il lavoro è completato quando viene determinato perché una richiesta valida può completarsi senza impostare on_url_called e viene aggiunta o aggiornata la copertura per questo comportamento.

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

Valutazione

Stack tecnologico
python
Ambito
backend, networking
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.