Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultipartReader doesn't work with -OO #1969

Closed
iceboy233 opened this issue Jun 10, 2017 · 7 comments
Closed

MultipartReader doesn't work with -OO #1969

iceboy233 opened this issue Jun 10, 2017 · 7 comments
Labels

Comments

@iceboy233
Copy link
Member

iceboy233 commented Jun 10, 2017

Long story short

MultipartReader doesn't work when -OO is enabled on python interpreter.

Expected behaviour

from aiohttp import web

async def hello(request):
    async for part in await request.multipart():
        print(part.name)
    return web.Response()

app = web.Application()
app.router.add_post('/', hello)
web.run_app(app)
curl 'http://localhost:8080' \
    -H 'content-type: multipart/form-data; boundary=----BOUNDARY' \
    --data-binary $'------BOUNDARY\r\nContent-Disposition: form-data; name="key"\r\n\r\nvalue\r\n------BOUNDARY--\r\n'

Actual behaviour

When -OO is enabled (e.g. python3 -OO a.py), the request handling fails:

Error handling request
Traceback (most recent call last):
  File "/home/iceboy/.local/lib/python3.5/site-packages/aiohttp/web_protocol.py", line 421, in start
    resp = yield from self._request_handler(request)
  File "/home/iceboy/.local/lib/python3.5/site-packages/aiohttp/web.py", line 303, in _handle
    resp = yield from handler(request)
  File "a.py", line 4, in hello
    async for part in await request.multipart():
  File "/home/iceboy/.local/lib/python3.5/site-packages/aiohttp/multipart.py", line 560, in __anext__
    part = yield from self.next()
  File "/home/iceboy/.local/lib/python3.5/site-packages/aiohttp/multipart.py", line 594, in next
    yield from self._read_boundary()
  File "/home/iceboy/.local/lib/python3.5/site-packages/aiohttp/multipart.py", line 689, in _read_boundary
    % (chunk, self._boundary))
ValueError: Invalid boundary b'', expected b'------BOUNDARY'

Your environment

python 3.5.2
aiohttp 2.1.0

@asvetlov
Copy link
Member

Just for curiosity: why do you use optimization levels?

@iceboy233
Copy link
Member Author

Just for curiosity: why do you use optimization levels?

In the hope that it could be faster.

More interestingly benchmark shows that it's often slower (in 1-2%) with -OO. There must be something wrong.

@asvetlov
Copy link
Member

Python has very subtle optimizations on -OO, I think this mode is useless.

@fafhrd91
Copy link
Member

it disables assert and __debug__ which gives some improvement for benchmarks. For production it useless

@fafhrd91
Copy link
Member

fixed in master

@kxepal you should be careful with assert, it should not have side-effects

@kxepal
Copy link
Member

kxepal commented Jun 18, 2017

Good catch! My bad to forget about PYTHONOPTIMIZE mode /)_-

@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants