miguelgrinberg / python-socketio

Python Socket.IO server and client
MIT License
3.98k stars 587 forks source link

After disconnect raise CancelledError #110

Closed MaxOvcharov closed 5 years ago

MaxOvcharov commented 7 years ago

I have strange errors after users are disconnected:

Error handling request
Traceback (most recent call last):
  File "/home/max/bot_project/mobile_mos_ru_backend/venv/lib/python3.5/site-packages/engineio/asyncio_socket.py", line 180, in _websocket_handler
    p = await asyncio.wait_for(wait_task, self.server.ping_timeout)
  File "/usr/lib/python3.5/asyncio/tasks.py", line 385, in wait_for
    yield from waiter
  File "/usr/lib/python3.5/asyncio/futures.py", line 361, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 296, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 266, in result
    raise CancelledError
concurrent.futures._base.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/max/bot_project/mobile_mos_ru_backend/venv/lib/python3.5/site-packages/aiohttp/web_protocol.py", line 421, in start
    resp = yield from self._request_handler(request)
  File "/home/max/bot_project/mobile_mos_ru_backend/venv/lib/python3.5/site-packages/aiohttp/web.py", line 303, in _handle
    resp = yield from handler(request)
  File "/home/max/bot_project/mobile_mos_ru_backend/venv/lib/python3.5/site-packages/engineio/asyncio_server.py", line 137, in handle_request
    packets = await socket.handle_get_request(environ)
  File "/home/max/bot_project/mobile_mos_ru_backend/venv/lib/python3.5/site-packages/engineio/asyncio_socket.py", line 73, in handle_get_request
    return await getattr(self, '_upgrade_' + transport)(environ)
  File "/home/max/bot_project/mobile_mos_ru_backend/venv/lib/python3.5/site-packages/engineio/asyncio_socket.py", line 120, in _upgrade_websocket
    return await ws(environ)
  File "/home/max/bot_project/mobile_mos_ru_backend/venv/lib/python3.5/site-packages/engineio/async_aiohttp.py", line 95, in __call__
    await self.handler(self)
  File "/home/max/bot_project/mobile_mos_ru_backend/venv/lib/python3.5/site-packages/engineio/asyncio_socket.py", line 187, in _websocket_handler
    wait_task.exception()
  File "/usr/lib/python3.5/asyncio/futures.py", line 288, in exception
    raise InvalidStateError('Exception is not set.')
asyncio.futures.InvalidStateError: Exception is not set.

What does this traceback mean?

miguelgrinberg commented 7 years ago

This is not your application's fault. The code that errored is there to try to compensate for a bug in asyncio, but it appears it isn't working as I expected. Fix coming shortly.

MaxOvcharov commented 7 years ago

Hi, I'm update socket.io to: python-engineio==1.7.0 python-socketio==1.7.6

Firstly I have this kind of errors: OSError [2017-07-06 10:32:10] DEBUG [app.test_connect:396] CONNECT TRANSPORT MODE[364] (8bbee9a974224b8a9bdb9ddbe6f73b8a): polling socket.accept() out of system resource socket: <socket.socket fd=12, family=AddressFamily.AF_INET, type=2049, proto=6, laddr=('127.0.0.1', 8080)> Traceback (most recent call last): File "/usr/lib/python3.5/asyncio/selector_events.py", line 161, in _accept_connection File "/usr/lib/python3.5/socket.py", line 195, in accept OSError: [Errno 24] Too many open files Error handling request Traceback (most recent call last): File "/home/max/bot_project/mobile_mos_ru_backend/venv/lib/python3.5/site-packages/aiohttp/web_protocol.py", line 422, in start resp = yield from self._request_handler(request) File "/home/max/bot_project/mobile_mos_ru_backend/venv/lib/python3.5/site-packages/aiohttp/web.py", line 306, in _handle resp = yield from handler(request) File "/home/max/bot_project/mobile_mos_ru_backend/chat/views.py", line 14, in index OSError: [Errno 24] Too many open files: '/home/max/bot_project/mobile_mos_ru_backend/chat/templates/app.html' Error handling request

And 2 minutes after: OSError Error handling request Traceback (most recent call last): File "/home/max/bot_project/mobile_mos_ru_backend/venv/lib/python3.5/site-packages/aiohttp/web_protocol.py", line 422, in start resp = yield from self._request_handler(request) File "/home/max/bot_project/mobile_mos_ru_backend/venv/lib/python3.5/site-packages/aiohttp/web.py", line 306, in _handle resp = yield from handler(request) File "/home/max/bot_project/mobile_mos_ru_backend/venv/lib/python3.5/site-packages/engineio/asyncio_server.py", line 146, in handle_request packets = await socket.handle_get_request(environ) File "/home/max/bot_project/mobile_mos_ru_backend/venv/lib/python3.5/site-packages/engineio/asyncio_socket.py", line 75, in handle_get_request return await getattr(self, '_upgrade_' + transport)(environ) File "/home/max/bot_project/mobile_mos_ru_backend/venv/lib/python3.5/site-packages/engineio/asyncio_socket.py", line 116, in _upgrade_websocket return await ws(environ) File "/home/max/bot_project/mobile_mos_ru_backend/venv/lib/python3.5/site-packages/engineio/async_aiohttp.py", line 95, in __call__ await self.handler(self) File "/home/max/bot_project/mobile_mos_ru_backend/venv/lib/python3.5/site-packages/engineio/asyncio_socket.py", line 136, in _websocket_handler pkt = await ws.wait() File "/home/max/bot_project/mobile_mos_ru_backend/venv/lib/python3.5/site-packages/engineio/async_aiohttp.py", line 111, in wait raise IOError()

OSError ^CException in callback BaseSelectorEventLoop._start_serving(<aiohttp.web_...x7f0c0a6e7278>, <socket.socke...2049, proto=6>, None, <Server sockets=None>) handle: <TimerHandle when=1890945.561715255 BaseSelectorEventLoop._start_serving(<aiohttp.web_...x7f0c0a6e7278>, <socket.socke...2049, proto=6>, None, <Server sockets=None>)> Traceback (most recent call last): File "/usr/lib/python3.5/asyncio/events.py", line 125, in _run self._callback(*self._args) File "/usr/lib/python3.5/asyncio/selector_events.py", line 156, in _start_serving protocol_factory, sock, sslcontext, server) File "/usr/lib/python3.5/asyncio/selector_events.py", line 234, in add_reader key = self._selector.get_key(fd) File "/usr/lib/python3.5/selectors.py", line 189, in get_key return mapping[fileobj] File "/usr/lib/python3.5/selectors.py", line 70, in __getitem__ fd = self._selector._fileobj_lookup(fileobj) File "/usr/lib/python3.5/selectors.py", line 224, in _fileobj_lookup return _fileobj_to_fd(fileobj) File "/usr/lib/python3.5/selectors.py", line 41, in _fileobj_to_fd raise ValueError("Invalid file descriptor: {}".format(fd)) ValueError: Invalid file descriptor: -1

MaxOvcharov commented 7 years ago

Does the first part of my traceback meens, that for every connection my server opens another instance of file '/home/max/bot_project/mobile_mos_ru_backend/chat/templates/app.html' ?

miguelgrinberg commented 7 years ago

@MaxOvcharov I haven't seen the code, but my first guess would be a file handle leak in the application. Make sure you close all your handles when you are done with them.

miguelgrinberg commented 5 years ago

This issue will be automatically closed due to being inactive for more than six months. Please reopen if you need more assistance.