ashleysommer / sanic-oauthlib

Sanic port of flask-oauthlib
BSD 3-Clause "New" or "Revised" License
3 stars 2 forks source link

Unclosed connections #1

Closed shaneseaton closed 4 years ago

shaneseaton commented 4 years ago

Hi,

"Long time listener, first time caller"

I found a couple of warning's using the library. It looks like there are call made to the aiohttp library that are not being closed. Hope this stack trace helps.

 Unclosed client session
 client_session: <aiohttp.client.ClientSession object at 0x7f1d66622828>
 source_traceback: Object created at (most recent call last):
   File "app.py", line 196, in <module>
     app.run(host=host, port=port, debug=config.DEBUG, auto_reload=config.AUTO_RELOAD)
   File "/usr/local/lib/my-app/.venv/lib/python3.6/site-packages/sanic/app.py", line 1135, in run
     serve(**server_settings)
   File "/usr/local/lib/my-app/.venv/lib/python3.6/site-packages/sanic/server.py", line 803, in serve
     loop.run_forever()
   File "/usr/lib/python3.6/asyncio/coroutines.py", line 126, in send
     return self.gen.send(value)
   File "/usr/local/lib/my-app/.venv/lib/python3.6/site-packages/spf/framework.py", line 555, in _handle_request
     stream_callback)
   File "/usr/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
     return self.gen.send(None)
   File "/usr/local/lib/my-app/.venv/lib/python3.6/site-packages/sanic/app.py", line 944, in handle_request
     response = await response
   File "/usr/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
     return self.gen.send(None)
   File "/usr/local/lib/my-app/.venv/lib/python3.6/site-packages/sanic_restplus/api.py", line 445, in wrapper
     resp = await resp
   File "/usr/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
     return self.gen.send(None)
   File "/usr/local/lib/my-app/.venv/lib/python3.6/site-packages/sanic_restplus/resource.py", line 112, in dispatch_request
     resp = await resp
   File "/usr/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
     return self.gen.send(None)
   File "/usr/local/lib/my-app/src/auth_functions.py", line 28, in decorated
     user = await self.authenticate(request, auth, password)
   File "/usr/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
     return self.gen.send(None)
   File "/usr/local/lib/my-app/src/auth_functions.py", line 49, in authenticate
     return await self.verify_token_callback(token)
   File "/usr/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
     return self.gen.send(None)
   File "/usr/local/lib/my-app/src/auth_functions.py", line 68, in verify_token
     profile = await get_profile(None, token)
   File "/usr/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
     return self.gen.send(None)
   File "/usr/local/lib/my-app/src/oauth2_routes.py", line 181, in get_profile
     resp = await remote.get("/api/profile", token=access_token)
   File "/usr/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
     return self.gen.send(None)
   File "/usr/local/lib/my-app/.venv/lib/python3.6/site-packages/sanic_oauthlib/client.py", line 486, in get
     return await self.request(*args, **kwargs)
   File "/usr/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
     return self.gen.send(None)
   File "/usr/local/lib/my-app/.venv/lib/python3.6/site-packages/sanic_oauthlib/client.py", line 572, in request
     uri, headers, data=to_bytes(body, self.encoding), method=method
   File "/usr/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
     return self.gen.send(None)
   File "/usr/local/lib/my-app/.venv/lib/python3.6/site-packages/sanic_oauthlib/client.py", line 476, in http_request
     http_session = aiohttp.ClientSession()
 Unclosed connector
 connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7f1d662be320>, 3747.448)]']
 connector: <aiohttp.connector.TCPConnector object at 0x7f1d66622908>
 source_traceback: Object created at (most recent call last):
   File "app.py", line 196, in <module>
     app.run(host=host, port=port, debug=config.DEBUG, auto_reload=config.AUTO_RELOAD)
   File "/usr/local/lib/my-app/.venv/lib/python3.6/site-packages/sanic/app.py", line 1135, in run
     serve(**server_settings)
   File "/usr/local/lib/my-app/.venv/lib/python3.6/site-packages/sanic/server.py", line 803, in serve
     loop.run_forever()
   File "/usr/lib/python3.6/asyncio/coroutines.py", line 126, in send
     return self.gen.send(value)
   File "/usr/local/lib/my-app/.venv/lib/python3.6/site-packages/spf/framework.py", line 555, in _handle_request
     stream_callback)
   File "/usr/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
     return self.gen.send(None)
   File "/usr/local/lib/my-app/.venv/lib/python3.6/site-packages/sanic/app.py", line 944, in handle_request
     response = await response
   File "/usr/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
     return self.gen.send(None)
   File "/usr/local/lib/my-app/.venv/lib/python3.6/site-packages/sanic_restplus/api.py", line 445, in wrapper
     resp = await resp
   File "/usr/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
     return self.gen.send(None)
   File "/usr/local/lib/my-app/.venv/lib/python3.6/site-packages/sanic_restplus/resource.py", line 112, in dispatch_request
     resp = await resp
   File "/usr/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
     return self.gen.send(None)
   File "/usr/local/lib/my-app/src/auth_functions.py", line 28, in decorated
     user = await self.authenticate(request, auth, password)
   File "/usr/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
     return self.gen.send(None)
   File "/usr/local/lib/my-app/src/auth_functions.py", line 49, in authenticate
     return await self.verify_token_callback(token)
   File "/usr/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
     return self.gen.send(None)
   File "/usr/local/lib/my-app/src/auth_functions.py", line 68, in verify_token
     profile = await get_profile(None, token)
   File "/usr/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
     return self.gen.send(None)
   File "/usr/local/lib/my-app/src/oauth2_routes.py", line 181, in get_profile
     resp = await remote.get("/api/profile", token=access_token)
   File "/usr/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
     return self.gen.send(None)
   File "/usr/local/lib/my-app/.venv/lib/python3.6/site-packages/sanic_oauthlib/client.py", line 486, in get
     return await self.request(*args, **kwargs)
   File "/usr/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
     return self.gen.send(None)
   File "/usr/local/lib/my-app/.venv/lib/python3.6/site-packages/sanic_oauthlib/client.py", line 572, in request
     uri, headers, data=to_bytes(body, self.encoding), method=method
   File "/usr/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
     return self.gen.send(None)
   File "/usr/local/lib/my-app/.venv/lib/python3.6/site-packages/sanic_oauthlib/client.py", line 476, in http_request
     http_session = aiohttp.ClientSession()
   File "/usr/local/lib/my-app/.venv/lib/python3.6/site-packages/aiohttp/client.py", line 213, in __init__
     connector = TCPConnector(loop=loop)
   File "/usr/local/lib/my-app/.venv/lib/python3.6/site-packages/aiohttp/connector.py", line 731, in __init__
     loop=loop)
ashleysommer commented 4 years ago

Fixed by https://github.com/ashleysommer/sanic-oauthlib/commit/4e6a7ae206f750d68fb0d6822d7d26e5516c21df