Skip to content

Add missing await in AioHttpIntegration.#261

Merged
untitaker merged 2 commits into
getsentry:masterfrom
janLo:fix-missing-await-aiohttp
Feb 12, 2019
Merged

Add missing await in AioHttpIntegration.#261
untitaker merged 2 commits into
getsentry:masterfrom
janLo:fix-missing-await-aiohttp

Conversation

@janLo

@janLo janLo commented Feb 12, 2019

Copy link
Copy Markdown
Contributor

The replaced _handle method of aiohttp.web.Application is a coroutine
itself. So it has to await the call to the original handle otherwise its
never awaited.

This fixes #260

Signed-off-by: Jan Losinski losinski@wh2.tu-dresden.de

@untitaker

Copy link
Copy Markdown
Member

I admit I don't understand the async story in Python. I assumed directly returning a coroutine in an async function would be equivalent.

Could you write a test for this? You should be able to do this:

init(integrations=[AioHttpIntegration()])
init()

and copy the rest from an existing test.

@codecov-io

codecov-io commented Feb 12, 2019

Copy link
Copy Markdown

Codecov Report

Merging #261 into master will decrease coverage by 0.72%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #261      +/-   ##
==========================================
- Coverage   81.74%   81.01%   -0.73%     
==========================================
  Files          32       32              
  Lines        2750     2750              
  Branches      444      444              
==========================================
- Hits         2248     2228      -20     
- Misses        340      362      +22     
+ Partials      162      160       -2
Impacted Files Coverage Δ
sentry_sdk/integrations/aiohttp.py 89.09% <100%> (+3.63%) ⬆️
sentry_sdk/integrations/aws_lambda.py 0% <0%> (-19.63%) ⬇️
sentry_sdk/worker.py 87.5% <0%> (-1.25%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3f9d748...268c7bb. Read the comment docs.

@janLo

janLo commented Feb 12, 2019

Copy link
Copy Markdown
Contributor Author

The problem is, that if you call a Coroutine (something with async def) you get a coroutine object back. To get the actual return (or exception or whatever is the result of the coroutine) you need to await it. So returning a coroutine from a coroutine (without the await inside) means, that you need to write await twice.

I'll check the test situation.

@untitaker

untitaker commented Feb 12, 2019

Copy link
Copy Markdown
Member

nvm, yes, brainfart. I think I was too much in Rust's async support where using a return means you would have to return an actual future.

@janLo

janLo commented Feb 12, 2019

Copy link
Copy Markdown
Contributor Author

Btw, urllib3 and certifi seems to be missing in the test requirements

@untitaker

Copy link
Copy Markdown
Member

I assume you did this:

pip install -r test-requirements.txt

while I usually do this in addition:

pip install -e .

@untitaker

Copy link
Copy Markdown
Member

try this: sh scripts/runtox.sh aiohttp

There are a lot of "optional test requirements" because some things don't work in certain python versions.

This demonstrates the behaviour in getsentry#260.

Signed-off-by: Jan Losinski <losinski@wh2.tu-dresden.de>
The replaced _handle method of aiohttp.web.Application is a coroutine
itself. So it has to await the call to the original handle otherwise its
never awaited.

This fixes getsentry#260

Signed-off-by: Jan Losinski <losinski@wh2.tu-dresden.de>
@janLo
janLo force-pushed the fix-missing-await-aiohttp branch from e100d1f to 268c7bb Compare February 12, 2019 14:17
@janLo

janLo commented Feb 12, 2019

Copy link
Copy Markdown
Contributor Author

There is now a unittest that fails without the fix and works with it :)

@untitaker
untitaker merged commit 085f47e into getsentry:master Feb 12, 2019
@untitaker

Copy link
Copy Markdown
Member

Awesome, thanks!

@janLo
janLo deleted the fix-missing-await-aiohttp branch February 12, 2019 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Half installed AioHttpIntegration causes aiohttp to crash

3 participants