MagicStack / MagicStack/httptools
`on_url` not called intermittently?
未關閉
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 1.3k
- 分支
- 107
- PR 合併指標
- 30 天內沒有已合併 PR
描述
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!
貢獻指南
這個儲存庫沒有索引到貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
使用 test_httptools.py 中的腳本以及報告中描述的 ab 基準測試,重現間歇性故障。從 HttpRequestParser 和 parser.feed_data 開始,接著追蹤請求資料如何到達 Request.on_url。當確定有效請求為何可以在未設定 on_url_called 的情況下完成,並為該行為新增或更新覆蓋測試後,即視為完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend, networking
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100