harvimt / quamash

Implementation of the PEP 3156 event-loop (asyncio) api using the Qt Event-Loop
BSD 2-Clause "Simplified" License
265 stars 46 forks source link

SSL handshakes crashes quamash #47

Closed Insoleet closed 8 years ago

Insoleet commented 9 years ago

Hello,

The following test :

import sys
import unittest
import asyncio
import aiohttp
import logging
import quamash
from quamash import QApplication

class Bug(unittest.TestCase):
    def setUp(self):
        self.qapplication = QApplication([])
        self.lp = quamash.QEventLoop(self.qapplication)
        asyncio.set_event_loop(self.lp)
        self.except_raised = False
        self.lp.set_exception_handler(lambda loop, context: self.exception_handler(loop, context))

    def exception_handler(self, loop, context):
        message = context.get('message')
        if not message:
            message = 'Unhandled exception in event loop'

        try:
            exception = context['exception']
        except KeyError:
            exc_info = False
        else:
            exc_info = (type(exception), exception, exception.__traceback__)

        log_lines = [message]
        for key in [k for k in sorted(context) if k not in {'message', 'exception'}]:
            log_lines.append('{}: {!r}'.format(key, context[key]))

        self.fail('\n'.join(log_lines))

    def test_bug(self):
        @asyncio.coroutine
        def request():
            response = yield from aiohttp.get("https://google.fr")
            self.assertEqual(response.status, 200)
            json = yield from response.json()
            self.assertTrue('+1' in json)

        @asyncio.coroutine
        def waiting():
            tasks = []
            task = asyncio.async(request())
            tasks.append(task)
            yield from asyncio.wait(tasks)

        self.lp.run_until_complete(request())
        try:
            self.lp.close()
        finally:
            asyncio.set_event_loop(None)

if __name__ == '__main__':
    logging.basicConfig(stream=sys.stderr)
    logging.getLogger().setLevel(logging.DEBUG)
    unittest.main()

Crashes quamash with the following error :

AssertionError: Exception in callback QEventLoop.__notifier_cb_wrapper({10: <PyQt5.QtCore...x7f6c96974a68>, 22: <PyQt5.QtCore...x7f6c88437708>}, <PyQt5.QtCore...x7f6c884375e8>, 22, <bound method..., bufsize=0>>>, (None,))
handle: <Handle QEventLoop.__notifier_cb_wrapper({10: <PyQt5.QtCore...x7f6c96974a68>, 22: <PyQt5.QtCore...x7f6c88437708>}, <PyQt5.QtCore...x7f6c884375e8>, 22, <bound method..., bufsize=0>>>, (None,))>
Unhandled error in custom exception handler
context: {'message': 'Exception in callback QEventLoop.__notifier_cb_wrapper({10: <PyQt5.QtCore...x7f6c96974a68>, 22: <PyQt5.QtCore...x7f6c88437c18>}, <PyQt5.QtCore...x7f6c88437708>, 22, <bound method..., bufsize=0>>>, (None,))', 'exception': TypeError("disconnect() failed between 'activated' and all its connections",), 'handle': <Handle QEventLoop.__notifier_cb_wrapper({10: <PyQt5.QtCore...x7f6c96974a68>, 22: <PyQt5.QtCore...x7f6c88437c18>}, <PyQt5.QtCore...x7f6c88437708>, 22, <bound method..., bufsize=0>>>, (None,))>}
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/events.py", line 120, in _run
    self._callback(*self._args)
  File "/usr/lib/python3.4/site-packages/quamash/__init__.py", line 458, in __notifier_cb_wrapper
    notifier.activated.disconnect()
TypeError: disconnect() failed between 'activated' and all its connections
harvimt commented 9 years ago

this is just a test for #45 right?

harvimt commented 9 years ago

Also there probably shouldn't be a test that depends on aiohttp

Insoleet commented 9 years ago

No this is not related to the ProactorLoop.

This bug happen on Linux and Windows, using the "default" event loop.

This test is mostly here to show the bug. It is probably needed to discover what is the real cause of the crash, so that the test would not depend on aiohttp.

Insoleet commented 8 years ago

Fixed with aiohttp@0.19 and python 3.5.