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

Clean shutdown #62

Closed
2Cubed opened this issue Oct 13, 2016 · 5 comments
Closed

Clean shutdown #62

2Cubed opened this issue Oct 13, 2016 · 5 comments
Assignees
Milestone

Comments

@2Cubed
Copy link
Member

2Cubed commented Oct 13, 2016

When sent a KeyboardInterrupt, the bot should gracefully close all websockets and display a shutdown message, rather than spewing out all sorts of asyncio error nonsense.

@2Cubed 2Cubed added this to the v0.4 milestone Oct 13, 2016
@2Cubed 2Cubed self-assigned this Nov 3, 2016
@Innectic Innectic self-assigned this Dec 25, 2016
@2Cubed
Copy link
Member Author

2Cubed commented Dec 29, 2016

Much of the "spam" seems to be coming from not closing ClientResponses from the base API class. Need to look into this - if left running for long periods of time, it could become a serious memory hog.

@2Cubed 2Cubed modified the milestones: v0.4, v0.4.1 Mar 3, 2017
@pylang
Copy link

pylang commented Mar 28, 2017

This issue suggests session.close() must be explicitly called. I'm hoping async with will handle this in the future.

Note: For reference, I add the following:

As mentioned in the Discord, one option might be chaining close commands for all opened sessions. See a rough idea using simple files in this SO post. From this inspiration, it may be possible to add names of opened sessions (or instances) to a list of classes that inherit ClientSession, e.g. API and Websocket, then call session.closed() on each by iteration.

@2Cubed
Copy link
Member Author

2Cubed commented Mar 28, 2017

Current "State of the Explosions™":

^CTraceback (most recent call last):
  File "run.py", line 46, in <module>
    loop.run_until_complete(run())
  File "/usr/lib/python3.6/asyncio/base_events.py", line 454, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.6/asyncio/base_events.py", line 421, in run_forever
    self._run_once()
  File "/usr/lib/python3.6/asyncio/base_events.py", line 1389, in _run_once
    event_list = self._selector.select(timeout)
  File "/usr/lib/python3.6/selectors.py", line 445, in select
    fd_event_list = self._epoll.poll(timeout, max_ev)
KeyboardInterrupt
2017-03-28 02:04:24 ERROR asyncio default_exception_handler: Unclosed client session
client_session: <cactusbot.api.CactusAPI object at 0x7f523c9c7d30>
2017-03-28 02:04:24 ERROR asyncio default_exception_handler: Unclosed client session
client_session: <cactusbot.services.beam.api.BeamAPI object at 0x7f523b8c9588>
2017-03-28 02:04:24 ERROR asyncio default_exception_handler: Unclosed client session
client_session: <cactusbot.services.beam.constellation.BeamConstellation object at 0x7f523a84bf60>
2017-03-28 02:04:24 ERROR asyncio default_exception_handler: Unclosed client session
client_session: <cactusbot.services.beam.chat.BeamChat object at 0x7f523a877898>
2017-03-28 02:04:24 ERROR asyncio default_exception_handler: Unclosed response
client_response: <ClientResponse(wss://constellation.beam.pro) [101 Switching Protocols]>
<CIMultiDictProxy('Date': 'Tue, 28 Mar 2017 06:04:21 GMT', 'Connection': 'upgrade', 'Set-Cookie': '__cfduid=da921f6ac8042c15ddebab17be0b10fee1490681060; expires=Wed, 28-Mar-18 06:04:20 GMT; path=/; domain=.beam.pro; HttpOnly', 'Upgrade': 'websocket', 'Sec-Websocket-Accept': '5Yi/47qTD/aKRhK+Yil8eweKWyk=', 'Server': 'cloudflare-nginx', 'Cf-Ray': '34686436dbee23a8-IAD')>

2017-03-28 02:04:24 ERROR asyncio default_exception_handler: Unclosed response
client_response: <ClientResponse(wss://chat3-dal.beam.pro:443) [101 Switching Protocols]>
<CIMultiDictProxy('Date': 'Tue, 28 Mar 2017 06:04:21 GMT', 'Connection': 'upgrade', 'Set-Cookie': '__cfduid=d7adeb860485d9fb833dad6ab2e0a2d741490681061; expires=Wed, 28-Mar-18 06:04:21 GMT; path=/; domain=.beam.pro; HttpOnly', 'Upgrade': 'websocket', 'Sec-Websocket-Accept': 'XHnsvZWAmsOJ7KYB9A0Pd2W3csQ=', 'Server': 'cloudflare-nginx', 'Cf-Ray': '346864389c640862-IAD')>

2017-03-28 02:04:24 ERROR asyncio default_exception_handler: Task was destroyed but it is pending!
task: <Task pending coro=<WebSocket.read() running at /home/user/Documents/Cactus/CactusBot/cactusbot/services/websocket.py:69> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f523b97fa38>()]>>
2017-03-28 02:04:24 ERROR asyncio default_exception_handler: Unclosed response
client_response: <ClientResponse(wss://cactus.exoz.one/sepal) [101 Switching Protocols]>
<CIMultiDictProxy('Date': 'Tue, 28 Mar 2017 06:04:20 GMT', 'Connection': 'upgrade', 'Set-Cookie': '__cfduid=daf67f7da4e5c439932bae81c1253cba11490681060; expires=Wed, 28-Mar-18 06:04:20 GMT; path=/; domain=.exoz.one; HttpOnly', 'Upgrade': 'websocket', 'Sec-Websocket-Accept': 'JHb+d4wWSFSms4OngQ8ldcoLQio=', 'Server': 'cloudflare-nginx', 'Cf-Ray': '34686431496a0f2d-IAD')>

2017-03-28 02:04:24 ERROR asyncio default_exception_handler: Task was destroyed but it is pending!
task: <Task pending coro=<WebSocket.read() running at /home/user/Documents/Cactus/CactusBot/cactusbot/services/websocket.py:69> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f523fa17918>()]>>
  • base interrupt trace
  • unclosed aiohttp.ClientSessions
  • unclosed aiohttp.ClientResponses
  • destroyed asyncio.Tasks

@2Cubed 2Cubed modified the milestones: v0.4.1, v0.4.2 Jul 13, 2017
@2Cubed
Copy link
Member Author

2Cubed commented Dec 10, 2017

No longer relevant.

@2Cubed 2Cubed closed this as completed Dec 10, 2017
@pylang
Copy link

pylang commented Dec 11, 2017

How come?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants